-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Autocomplete] Fix Multiple tag delete action #18153
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -607,8 +607,7 @@ export default function useAutocomplete(props) { | |
selectNewValue(event, filteredOptions[highlightedIndexRef.current]); | ||
}; | ||
|
||
const handleTagDelete = event => { | ||
const index = Number(event.currentTarget.getAttribute('data-tag-index')); | ||
const handleTagDelete = index => event => { | ||
const newValue = [...value]; | ||
newValue.splice(index, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oliviertassinari Just wanted to know, why are we using splice here. For example i am having 3 values selected [1,2,3] and trying to delete first element in the array, in this case we will be passing index as 0 to renderTagProps. So if you splice array with 0,1 (newValue.splice(0,1)) will return first element in the array [1]. We are facing issue like if we try to delete any element in our selected value list, it always removes last element instead of actual element which we try to delete. |
||
handleValue(event, newValue); | ||
|
@@ -699,8 +698,11 @@ export default function useAutocomplete(props) { | |
event.preventDefault(); | ||
}, | ||
}), | ||
getTagProps: () => ({ | ||
onDelete: handleTagDelete, | ||
getTagProps: ({ index }) => ({ | ||
key: index, | ||
'data-tag-index': index, | ||
tabIndex: -1, | ||
onDelete: handleTagDelete(index), | ||
}), | ||
getListboxProps: () => ({ | ||
role: 'listbox', | ||
|
@@ -716,9 +718,9 @@ export default function useAutocomplete(props) { | |
const disabled = getOptionDisabled ? getOptionDisabled(option) : false; | ||
|
||
return { | ||
key: index, | ||
tabIndex: -1, | ||
role: 'option', | ||
key: index, | ||
id: `${id}-option-${index}`, | ||
onMouseOver: handleOptionMouseOver, | ||
onClick: handleOptionClick, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eps1lon any better idea for this selector?