-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(selector): open the menu below by default #4976
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
AKnassa
wants to merge
1
commit into
facebook:main
Choose a base branch
from
AKnassa:rocky/issue-4227-selector-below-default
base: main
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
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
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,9 @@ | ||
| --- | ||
| '@astryxdesign/core': minor | ||
| --- | ||
|
|
||
| [breaking] Selector menus open below the trigger by default (#4227). The old native-select behavior — the open menu overlaying the trigger with the selected option pinned over it — is now opt-in via `hasSelectedItemOverlay`. `placement` keeps working as before and now documents its `'below'` default; Selector menus also gain the standard `--spacing-1` clearance that DropdownMenu, MultiSelector, and ComplexSelector already use (search mode included, which used to sit flush). | ||
|
|
||
| Why the flip: the overlay covered the trigger while it kept DOM focus (WCAG 2.4.11 focus-obscured territory), quietly degenerated once the selected option sat past the listbox fold (the menu pinned to the top of the viewport, including in the no-value placeholder state every form starts in), and made default Selector the odd one out — MultiSelector, ComplexSelector, DropdownMenu, and Selector-with-hasSearch all open below already. To restore the previous look on a given instance, add `hasSelectedItemOverlay`. | ||
|
|
||
| @AKnassa | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -531,15 +531,22 @@ interface SelectorPropsBase< | |
| searchPlaceholder?: string; | ||
|
|
||
| /** | ||
| * Position placement relative to the trigger. | ||
| * | ||
| * Omit to use the selector's default selected-item overlay behavior: the | ||
| * selected item is positioned over the trigger and clamped to the viewport. | ||
| * Set a placement to opt into explicit layer positioning (for example, | ||
| * Position placement relative to the trigger (for example, | ||
| * `placement="above"` for bottom-fixed toolbars). | ||
| * @default 'below' | ||
| */ | ||
| placement?: LayerPlacement; | ||
|
|
||
| /** | ||
| * Whether to overlay the open menu on the trigger so the selected option | ||
| * sits directly over it, like a native macOS select. The menu is pulled up | ||
| * by a measured offset and clamped to the viewport. Only applies with | ||
| * placement below (the default); an explicit non-below placement or | ||
| * hasSearch uses standard layer positioning instead. | ||
| * @default false | ||
| */ | ||
| hasSelectedItemOverlay?: boolean; | ||
|
Contributor
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. Superseded by the |
||
|
|
||
| /** | ||
| * Whether the dropdown starts open on mount. | ||
| * Useful for showcases and previews. | ||
|
|
@@ -671,6 +678,7 @@ export function Selector<T extends SelectorOptionType>( | |
| hasSearch = false, | ||
| searchPlaceholder: searchPlaceholderFromProps, | ||
| placement, | ||
| hasSelectedItemOverlay = false, | ||
| isDefaultOpen = false, | ||
| 'data-testid': testId, | ||
| width, | ||
|
|
@@ -829,10 +837,14 @@ export function Selector<T extends SelectorOptionType>( | |
| [announce, selectableItems], | ||
| ); | ||
|
|
||
| // Calculate offset to position selected item over trigger. Explicit | ||
| // placement opts out of the selector-specific overlay behavior and uses the | ||
| // standard layer positioning API instead. | ||
| const shouldOverlaySelectedItem = placement == null && !hasSearch; | ||
| // Calculate offset to position selected item over trigger. The overlay is | ||
| // opt-in (hasSelectedItemOverlay) and rides on below placement — an | ||
| // explicit non-below placement or search mode uses the standard layer | ||
| // positioning API instead. | ||
| const shouldOverlaySelectedItem = | ||
| hasSelectedItemOverlay && | ||
| !hasSearch && | ||
| (placement == null || placement === 'below'); | ||
| const {offset: rawOffset, isPositioned: rawIsPositioned} = | ||
| useSelectedItemOffset({ | ||
| isOpen: popover.isOpen && shouldOverlaySelectedItem, | ||
|
|
@@ -1412,6 +1424,12 @@ export function Selector<T extends SelectorOptionType>( | |
| { | ||
| placement: popoverPlacement, | ||
| alignment: 'start', | ||
| // Standard menu clearance (the DropdownMenu/MultiSelector recipe), | ||
| // except in overlay mode: there the measured negative margin owns | ||
| // the block geometry and must stay flush against the anchor. | ||
| offset: shouldOverlaySelectedItem | ||
| ? undefined | ||
| : spacingVars['--spacing-1'], | ||
| xstyle: [styles.popover, layerAnimations[popoverPlacement]], | ||
| style: popoverOffsetStyle, | ||
| }, | ||
|
|
||
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.
Search mode isn't flush any more, #5003 landed that. Needs a reword.