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

chore(react-tag-picker): ensure no toggle behaviour when re-selecting already selected data #33344

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
bsunderhus marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
"comment": "chore(react-tag-picker): ensure no toggle behaviour when re-selecting already selected data",
"packageName": "@fluentui/react-tag-picker",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useEventCallback, useId, useMergedRefs } from '@fluentui/react-utilities';
import { elementContains, useEventCallback, useId, useMergedRefs } from '@fluentui/react-utilities';
import type {
TagPickerOnOpenChangeData,
TagPickerOnOptionSelectData,
Expand Down Expand Up @@ -70,7 +70,6 @@ export const useTagPicker_unstable = (props: TagPickerProps): TagPickerState =>
});

const { trigger, popover } = childrenToTriggerAndPopover(props.children, noPopover);

return {
activeDescendantController,
components: {},
Expand Down Expand Up @@ -98,7 +97,23 @@ export const useTagPicker_unstable = (props: TagPickerProps): TagPickerState =>
getOptionsMatchingValue: comboboxState.getOptionsMatchingValue,
registerOption: comboboxState.registerOption,
selectedOptions: comboboxState.selectedOptions,
selectOption: comboboxState.selectOption,
selectOption: useEventCallback((event, data) => {
// if the option is already selected, invoke onOptionSelect callback with current selected values
// the combobox state would unselect the option, which is not the behavior expected
if (
comboboxState.selectedOptions.includes(data.value) &&
!elementContains(tagPickerGroupRef.current, event.target as Node)
) {
props.onOptionSelect?.(event, {
selectedOptions: comboboxState.selectedOptions,
value: data.value,
type: event.type,
event,
} as TagPickerOnOptionSelectData);
return;
}
comboboxState.selectOption(event, data);
}),
setHasFocus: comboboxState.setHasFocus,
setOpen: comboboxState.setOpen,
setValue: comboboxState.setValue,
Expand Down