-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(react-headless-components-preview): make Combobox expandIcon toggle the listbox #36574
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
Open
Dmytro Kirpa (dmytrokirpa)
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
dmytrokirpa:fix/headless-combobox-expand-icon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cfbacac
fix(react-headless-components-preview): make Combobox expandIcon togg…
dmytrokirpa 28e213f
update api snapshot
dmytrokirpa 6bc0dd3
refactor(react-combobox): share expandIcon slot logic via useCombobox…
dmytrokirpa 7e7b593
Merge branch 'master' into fix/headless-combobox-expand-icon
dmytrokirpa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-combobox-3f1c7a2e-9b41-4d5e-8c6a-1e2b7d4f0a93.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "feat: extract shared useComboboxExpandIconSlot hook for the Combobox expand icon slot", | ||
| "packageName": "@fluentui/react-combobox", | ||
| "email": "dmytrokirpa@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-headless-components-preview-combobox-expand-icon.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "fix: wire up Combobox expandIcon so it toggles the listbox and exposes button semantics", | ||
| "packageName": "@fluentui/react-headless-components-preview", | ||
| "email": "dmytrokirpa@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ct-components/react-combobox/library/src/components/Combobox/useComboboxExpandIconSlot.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { slot, useId } from '@fluentui/react-utilities'; | ||
| import type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities'; | ||
|
|
||
| export type UseComboboxExpandIconSlotOptions = { | ||
| /** Whether the combobox trigger is disabled. */ | ||
| disabled?: boolean; | ||
| /** Whether the listbox is currently open. */ | ||
| open: boolean; | ||
| /** `aria-label` passed to the combobox. */ | ||
| 'aria-label'?: string; | ||
| /** `aria-labelledby` passed to the combobox. */ | ||
| 'aria-labelledby'?: string; | ||
| /** `aria-labelledby` of the resolved trigger slot, used to build the labelling chain. */ | ||
| triggerLabelledBy?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Creates the `expandIcon` slot of a combobox: button semantics plus the default accessible name. | ||
| * Event handlers are layered on by the caller, since the toggle mechanics differ between the | ||
| * positioning-based and popover-based implementations. | ||
| */ | ||
| export function useComboboxExpandIconSlot( | ||
| expandIconFromProps: Slot<'span'> | undefined | null, | ||
| options: UseComboboxExpandIconSlotOptions, | ||
| ): SlotComponentType<ExtractSlotProps<Slot<'span'>>> | undefined { | ||
| const { disabled, open, triggerLabelledBy } = options; | ||
| const fallbackId = useId('combobox-chevron-'); | ||
|
|
||
| const expandIcon = slot.optional(expandIconFromProps, { | ||
| renderByDefault: true, | ||
| defaultProps: { | ||
| 'aria-disabled': disabled ? 'true' : undefined, | ||
| 'aria-expanded': open, | ||
| role: 'button', | ||
| }, | ||
| elementType: 'span', | ||
| }); | ||
|
|
||
| if (!expandIcon) { | ||
| return expandIcon; | ||
| } | ||
|
|
||
| // If there is no explicit aria-label, calculate default accName attribute for expandIcon button, | ||
| // using the following steps: | ||
| // 1. If there is an aria-label, it is "Open [aria-label]" | ||
| // 2. If there is an aria-labelledby, it is "Open [aria-labelledby target]" (using aria-labelledby + ids) | ||
| // 3. If there is no aria-label/ledby attr, it falls back to "Open" | ||
| // We can't fall back to a label/htmlFor name because of https://github.com/w3c/accname/issues/179 | ||
| const hasExpandLabel = expandIcon['aria-label'] || expandIcon['aria-labelledby']; | ||
| const defaultOpenString = 'Open'; // this is english-only since it is the fallback | ||
|
|
||
| if (!hasExpandLabel) { | ||
| if (options['aria-labelledby']) { | ||
| const chevronId = expandIcon.id ?? fallbackId; | ||
|
|
||
| expandIcon['aria-label'] = defaultOpenString; | ||
| expandIcon.id = chevronId; | ||
| expandIcon['aria-labelledby'] = `${chevronId} ${triggerLabelledBy}`; | ||
| } else if (options['aria-label']) { | ||
| expandIcon['aria-label'] = `${defaultOpenString} ${options['aria-label']}`; | ||
| } else { | ||
| expandIcon['aria-label'] = defaultOpenString; | ||
| } | ||
| } | ||
|
|
||
| return expandIcon; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-react-components/Menu Converged - submenuIndicator slotted content 2 screenshots
vr-tests-react-components/Positioning 2 screenshots
vr-tests-react-components/ProgressBar converged 3 screenshots
vr-tests-react-components/TagPicker 2 screenshots
There were 2 duplicate changes discarded. Check the build logs for more information.