Skip to content

Commit

Permalink
add createOnPaste option for select
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiTsybulskyi committed Apr 30, 2024
1 parent 25cd4ef commit 20e4ca0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/form/Select/MultiSelect.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const Createable = () => {
multiple
closeOnSelect={false}
createable
createOnPaste
selectOnKeys={['Enter', 'Space', 'Comma']}
searchOptions={{ threshold: 0 }}
placeholder="Add some categories or pick existing one..."
Expand Down
10 changes: 8 additions & 2 deletions src/form/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export interface SelectProps {
*/
createable?: boolean;

/**
* Whether you can create new options when paste text inside input.
*/
createOnPaste?: boolean;

/**
* The list of KeyCodes for creating select values.
* The default is ['Enter']
Expand Down Expand Up @@ -228,6 +233,7 @@ export const Select: FC<Partial<SelectProps>> = ({
placeholder,
disabled,
createable,
createOnPaste,
selectOnKeys,
loading,
multiple,
Expand Down Expand Up @@ -639,7 +645,7 @@ export const Select: FC<Partial<SelectProps>> = ({

const onPasteHandler = useCallback(
(e: React.ClipboardEvent<HTMLInputElement>) => {
if (createable && multiple) {
if (createOnPaste && multiple) {
const inputElement = e.target as HTMLInputElement;
const inputValue = inputElement.value;
const clipboardValue = e.clipboardData.getData('Text');
Expand All @@ -665,7 +671,7 @@ export const Select: FC<Partial<SelectProps>> = ({
}
},
[
createable,
createOnPaste,
multiple,
onChange,
onOptionsChange,
Expand Down

0 comments on commit 20e4ca0

Please sign in to comment.