-
Notifications
You must be signed in to change notification settings - Fork 2
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
Split Select dual popover/listbox element in two #1789
Conversation
cdfe295
to
701fe9c
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1789 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 67 67
Lines 1204 1203 -1
Branches 455 455
=========================================
- Hits 1204 1203 -1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
4e705bc
to
e655188
Compare
*/ | ||
function useListboxPositioning( | ||
function usePopoverPositioning( |
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.
I removed all references to "listbox" from this hook, because it is likely going to be extracted and decoupled from that.
e655188
to
87fe3a5
Compare
@@ -257,16 +257,16 @@ function SelectOption<T>({ | |||
|
|||
SelectOption.displayName = 'Select.Option'; | |||
|
|||
/** Small space to apply between the toggle button and the listbox */ |
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.
This PR is full of listbox
/popover
replacements.
.getDOMNode() | ||
.getBoundingClientRect(); | ||
|
||
assert.isTrue(listboxWidth < window.innerWidth); | ||
assert.isBelow(popoverWidth, window.innerWidth); |
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.
assert.isBelow(a, b)
generates a better error than assert.isTrue(a < b)
if the assertion fails.
87fe3a5
to
1018f95
Compare
// We don't want the listbox to ever render outside the viewport, | ||
// and we give it a 16px gap | ||
'max-w-[calc(100%-16px)]', | ||
// Overwrite [popover] default styles |
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.
What are the popover
default styles?
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.
It sets margin: auto
so that popovers are horizontally and vertically centered in the top layer. Unfortunately, it messes the positioning calculation.
It also sets padding: 0.25rem
, which adds-up to the manually set padding in the listbox.
Surprisingly, it didn't have any effect when [popover]
was used in a ul
element. I suspect it was because of the style resets that tailwind sets.
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.
aria-orientation="vertical" | ||
data-testid="select-listbox" | ||
data-listbox-open={listboxOpen} | ||
ref={popoverRef} | ||
// nb. Use `undefined` rather than `false` because Preact doesn't | ||
// handle boolean values correctly for this attribute (it will set | ||
// `popover="false"` instead of removing the attribute). |
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.
Incidentally I think this might be fixed now, but it needs testing.
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.
Yep. I considered changing it, but I think we can tackle it individually
This PR is the first of a series aiming to simplify/extract capabilities from the
Select
component.Here we are splitting the listbox-as-popover element into two independent elements:
div
which acts as the popover, using the popover API when possible, and handling positioning and openness logic.ul
with the listbox role, which handles accessibility aspects to handle a list of items, like aria attributes and keyboard navigation. It is the only children of the popover element.For now, this split is done inside of the
Select
component, keeping it unchanged from a consumer or user point of view.In follow-up PRs we'll we extracting some/all of those components.
Note
This PR renames many references to the
listbox
concept topopover
, but there are a few grey areas that I left unchanged.I expect some of those to be changed in upcoming PRs, where it will become more obvious as we start extracting sub-components.
Tip
This PR is easier to review ignoring whitespaces
Testing steps
Sanity-check that everything in http://localhost:4001/input-select looks and behaves the same as before this change.