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

[Select] Create options onPaste event #162

Merged
merged 3 commits into from
Apr 30, 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
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) {
Copy link
Member

Choose a reason for hiding this comment

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

Does it select if its already a 'created' option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

Copy link
Member

Choose a reason for hiding this comment

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

if creatable = false but I paste in a option this condition is invalid. I think it should be selectOnPaste then when combined w/ creatable would create them or of not just select them.

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
Loading