Skip to content

react-combobox: move Combobox functionality to shared hooks#23499

Merged
smhigley merged 14 commits intomicrosoft:masterfrom
smhigley:combobox-shared-hooks
Jun 23, 2022
Merged

react-combobox: move Combobox functionality to shared hooks#23499
smhigley merged 14 commits intomicrosoft:masterfrom
smhigley:combobox-shared-hooks

Conversation

@smhigley
Copy link
Copy Markdown
Contributor

This PR splits functionality in Combobox that will be shared with Dropdown into a folder of shared hooks. It depends on the changes in #23492 before it can be merged.

You can see where this fits into the larger combobox work (with some differences) in #22906

I'm very indifferent about the folder name "ComboboxBase", but I haven't really thought of a better one. I'm also happy to put the files in utils, but since they're so specific to the component slots and state, it made sense to me to have them in a separate folder.

@smhigley smhigley requested a review from a team as a code owner June 10, 2022 20:21
@github-actions github-actions bot added this to the June Project Cycle Q2 2022 milestone Jun 10, 2022
@smhigley smhigley marked this pull request as draft June 10, 2022 20:22
@fabricteam
Copy link
Copy Markdown
Collaborator

fabricteam commented Jun 10, 2022

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-combobox
Combobox
61.924 kB
21.232 kB
62.291 kB
21.341 kB
367 B
109 B

🤖 This report was generated against 675acea49c97f10837ddee9b8c4350ca27750125

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Jun 10, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 99e8f58:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@size-auditor
Copy link
Copy Markdown

size-auditor bot commented Jun 10, 2022

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: c446a15764655758650fc5ff865652abe8d9fa44 (build)

@smhigley smhigley force-pushed the combobox-shared-hooks branch from 139c9da to d30e1c2 Compare June 13, 2022 21:37
@smhigley smhigley marked this pull request as ready for review June 13, 2022 21:37
@smhigley smhigley closed this Jun 23, 2022
@smhigley smhigley reopened this Jun 23, 2022
@smhigley smhigley force-pushed the combobox-shared-hooks branch from e57d298 to 99e8f58 Compare June 23, 2022 17:29
@smhigley smhigley merged commit 24ee79d into microsoft:master Jun 23, 2022
ref: React.Ref<HTMLButtonElement | HTMLInputElement>,
triggerSlot?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,
listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,
): [ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>, ExtractSlotProps<Slot<typeof Listbox>>] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I could be wrong, but is not our pattern to return objects? (all other our hooks doing that except utility ones that mimic React's behavior)

// resolve listbox shorthand props
const listbox: typeof listboxSlot = {
multiselect,
tabIndex: undefined,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just wondering why tabIndex is required there as it overrides nothing...

setOpen(event, false);
break;
case 'CloseSelect':
!multiselect && setOpen(event, false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Can we prefer if conditions? It will not make code longer, but more readable 👍

if (!multiselect) {
  setOpen(event, false);
}

import type { ComboboxBaseProps } from './ComboboxBase.types';
import { Listbox } from '../components/Listbox/Listbox';

export function useComboboxPopup(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Naming is hard, but should not it be a popover to be consistent with Popover component? Or is it intentional?

Comment on lines +34 to +37
return [
{ ...triggerShorthand, ref: useMergedRefs(triggerShorthand?.ref, targetRef) },
{ ...listboxShorthand, ref: useMergedRefs(listboxShorthand?.ref, containerRef) },
];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other our hooks (use*Styles and etc.) are mutating the state instead of creating new object. Is it intentional there?

const { targetRef, containerRef } = usePositioning(popperOptions);

triggerShorthand.ref = useMergedRefs(triggerShorthand?.ref, targetRef)

Comment on lines +8 to +9
triggerShorthand?: ExtractSlotProps<Slot<'button'>>,
listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: We use term "shorthand" to unresolved slot props i.e. a union of string | number | SlotProps. Is there sense to rename it to triggerSlotProps & listboxSlotProps to make it clearer? (it will be a clear indicator that a shorthand was resolved to props already)

* Render the combobox's popup inline in the DOM.
* This has accessibility benefits, particularly for touch screen readers.
*/
inlinePopup?: boolean;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Curiosity: why it was renamed?

rohitpagariya pushed a commit to rohitpagariya/fluentui that referenced this pull request Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants