Skip to content

react-combobox: add separate Dropdown component#23550

Merged
smhigley merged 24 commits intomicrosoft:masterfrom
smhigley:dropdown
Jun 27, 2022
Merged

react-combobox: add separate Dropdown component#23550
smhigley merged 24 commits intomicrosoft:masterfrom
smhigley:dropdown

Conversation

@smhigley
Copy link
Copy Markdown
Contributor

This adds a Dropdown component to the react-combobox package, and updates Combobox to be an editable field with an <input> as the primary slot.

This PR depends on the changes in #23499

Note: there are some quirks with how the input behaves when selecting vs. typing that will be fixed in a separate PR.

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

fabricteam commented Jun 14, 2022

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-combobox
Combobox (including child components)
62.897 kB
21.536 kB
73.674 kB
23.896 kB
10.777 kB
2.36 kB
react-combobox
Dropdown (including child components)
0 B
0 B
73.203 kB
23.895 kB
🆕 New entry

🤖 This report was generated against 118f7ddaac0f7e1f705f5fb93af7722a35a27610

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Jun 14, 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 1cffa6c:

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

@size-auditor
Copy link
Copy Markdown

size-auditor bot commented Jun 14, 2022

Asset size changes

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

Baseline commit: 118f7ddaac0f7e1f705f5fb93af7722a35a27610 (build)

@smhigley smhigley marked this pull request as ready for review June 23, 2022 18:34
Comment on lines +39 to +40
const [triggerWithPopup, listboxWithPopup] = useComboboxPopup(props, triggerShorthand, listboxShorthand);
const [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerWithPopup, listboxWithPopup);
Copy link
Copy Markdown
Member

@layershifter layershifter Jun 27, 2022

Choose a reason for hiding this comment

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

As I mentioned in the other PR: probably these hooks should accept and return state to be consistent with other components:

const state = {/* ... */}

useComboboxPopup(state)
useComboboxTrigger(state)

return state

Copy link
Copy Markdown
Contributor Author

@smhigley smhigley Jun 27, 2022

Choose a reason for hiding this comment

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

I actually tried doing this initially, but the problem is essentially with typing. The issue is that Combobox vs. Dropdown have different and incompatible primary slot types (button vs. input, with different children types), and I didn't find a way to type the state prop and return type in a way that would work without a bunch of explicit as X casting.

The other reason is that I made Combobox's primary slot be input, and Dropdown's primary slot be button. This is mostly a stylistic opinion, but it ended up seeming cleaner to me to take/return the slot props themselves rather than have the hook check for e.g. if('input' in state) etc.

I'd be happy to work with you on that more, if you have any thoughts on how to make that work. For now, both hooks are fully internal and not exported, so we can change this as much as we want without affecting the public API :)

@layershifter
Copy link
Copy Markdown
Member

Bundle size report

Would you mind to add a bundle size fixture for Dropdown? 🐱

...shorthands.borderRadius(tokens.borderRadiusMedium),
boxSizing: 'border-box',
display: 'inline-block',
columnGap: tokens.spacingHorizontalXXS,
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.

gap

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed!

* Callback when the open/closed state of the dropdown changes
*/
onOpenChange?: (e: ComboboxOpenEvents, data: ComboboxOpenChangeData) => void;
onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void;
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: Not a fan of having Base in the type names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I know, I just can't think of anything else 😅

@smhigley smhigley merged commit 3fdf7b6 into microsoft:master Jun 27, 2022
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.

7 participants