Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to define custom keys to create values in select #145

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/form/Select/MultiSelect.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const Createable = () => {
multiple
closeOnSelect={false}
createable
valuesSplitterKeyCodes={['Enter', 'Space', 'Comma']}
selectOnKeys={['Enter', 'Space', 'Comma']}
placeholder="Add some categories or pick existing one..."
value={value}
onChange={v => setValue(v)}
Expand Down
12 changes: 7 additions & 5 deletions src/form/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ export interface SelectProps {

/**
* The list of KeyCodes for creating select values.
SerhiiTsybulskyi marked this conversation as resolved.
Show resolved Hide resolved
* The default is ['Enter']
* Typical options would be: ['Enter', 'Tab', 'Space', 'Comma']
*/
valuesSplitterKeyCodes?: string[];
selectOnKeys?: string[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we improve this type? Is there a keycode type the browser has we could use ?


/**
* The options of the select.
Expand Down Expand Up @@ -211,7 +213,7 @@ export const Select: FC<Partial<SelectProps>> = ({
placeholder,
disabled,
createable,
valuesSplitterKeyCodes,
selectOnKeys,
loading,
multiple,
error,
Expand Down Expand Up @@ -566,14 +568,14 @@ export const Select: FC<Partial<SelectProps>> = ({
onArrowDownKeyUp(event);
} else if (key === 'Escape') {
resetSelect();
} else if (valuesSplitterKeyCodes?.includes(key)) {
} else if (selectOnKeys?.includes(key)) {
onAddSelection(event);
}

onInputKeyUp?.(event);
},
[
valuesSplitterKeyCodes,
selectOnKeys,
onInputKeyUp,
onArrowUpKeyUp,
onArrowDownKeyUp,
Expand Down Expand Up @@ -711,7 +713,7 @@ export const Select: FC<Partial<SelectProps>> = ({

Select.defaultProps = {
clearable: true,
valuesSplitterKeyCodes: ['Enter'],
selectOnKeys: ['Enter'],
filterable: true,
menuPlacement: 'bottom-start',
closeOnSelect: true,
Expand Down
Loading