-
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
Prevent Select listbox to grow out of viewport #1746
Conversation
// Make items stretch so that all have the same height. This is | ||
// important for multi-selects, where the checkbox actionable surface | ||
// should span to the very edges of the option containing it. | ||
'flex justify-between items-stretch', |
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.
Truncating text did not properly work when nesting flex containers, so I simplified this to be a single flex container again, and making the checkbox for multi-selects be self-stretch
.
This not only solves the problem, but also simplifies the overall layout making it more clear.
6734f66
to
20afc2f
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1746 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 67 67
Lines 1195 1202 +7
Branches 449 452 +3
=========================================
+ Hits 1195 1202 +7 ☔ View full report in Codecov by Sentry. |
b21f473
to
ba1d1dc
Compare
if (!asPopover) { | ||
// Set styles for non-popover mode | ||
if (shouldListboxDropUp) { | ||
return setListboxCSSProps({ | ||
bottom: '100%', | ||
marginBottom: LISTBOX_TOGGLE_GAP, | ||
}); | ||
} | ||
|
||
return setListboxCSSProps({ top: '100%', marginTop: LISTBOX_TOGGLE_GAP }); |
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.
The logic for popover listboxes is now more complex, so I decided to flip this condition and move the rest of the logic down.
2f4acf6
to
e4df7e0
Compare
The I'm just now realizing that with the logic introduce here, we could get rid of it entirely, as a listbox would grow to the left "naturally" if it doesn't fit the viewport. This is a comparison of how the same |
Example of how these changes look when used in the LMS dashboard filters: listbox-in-viewport-dashboard-2024-10-25_14.19.58.mp4Since the options have complex content, it just needs a small change to truncate assignment names: diff --git a/lms/static/scripts/frontend_apps/components/dashboard/DashboardActivityFilters.tsx b/lms/static/scripts/frontend_apps/components/dashboard/DashboardActivityFilters.tsx
index 0cc31a9e0..d684abb69 100644
--- a/lms/static/scripts/frontend_apps/components/dashboard/DashboardActivityFilters.tsx
+++ b/lms/static/scripts/frontend_apps/components/dashboard/DashboardActivityFilters.tsx
@@ -92,7 +92,7 @@ function AssignmentOption({
return (
<MultiSelect.Option value={`${assignment.id}`} elementRef={elementRef}>
<div className="flex flex-col gap-0.5">
- {assignment.title}
+ <div className="truncate">{assignment.title}</div>
<div className="text-grey-6 text-xs">
{formatDateTime(assignment.created)}
</div> |
// sure it never increases the body size, which could cause horizontal | ||
// scrollbars to appear | ||
const regularAvailableSpace = | ||
(right ? buttonLeft + buttonWidth : bodyWidth - buttonLeft) - |
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.
The meaning of the existing right
function parameter is as clear as it could be. This ultimately comes from right
in BaseSelectProps
. That has some documentation but it could be improved. The summary reads "Align the listbox to the right." To the right of what?
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'm not sure if I follow. Are you suggesting to update the comment somewhere?
I think I would be inclined to keep it. The UI looks tidier if dropdowns on the right edge of the screen have their right edges exactly aligned with the toggle button, when there is space. |
62a1f82
to
51ceff5
Compare
Yeah, I tend to agree |
2ce951e
to
ad252d3
Compare
ad252d3
to
0d43c7a
Compare
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 had a query about the asymmetry in tests for left and right-aligned list boxes.
}); | ||
|
||
[ | ||
{ name: 'long name'.repeat(50), shouldGrow: true }, |
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 string is about 2300px wide on my system (using CanvasRenderingContext2D.measureText
). If the viewport happens to be really large in the test browser, it is possible the listbox might not need to grow.
0d43c7a
to
71e303b
Compare
I have consolidated the tests for left-aligned and right-aligned listboxes in a single test case with a dataset that covers 6 scenarios:
|
71e303b
to
85dd597
Compare
85dd597
to
336956f
Compare
This PR update the logic that calculates styles for the Select's listbox when it is displayed, so that it takes into consideration the body width when calculating its position.
When we detect the listbox would render outside of the viewport, we let it "grow" in the oposite direction instead, to prevent horizontal scrolling.
listbox-in-viewport-2024-10-24_10.46.58.mp4
listbox-in-viewport-right-2024-10-25_11.25.21.mp4
As a side effect, the listbox can now be smaller than its content in some circumstances. For that, we now provide a new prop to decide if the content should be truncated, or wrap multiple lines.
Truncate:
listbox-in-viewport-truncate-2024-10-24_10.40.23.mp4
Wrap:
listbox-in-viewport-wrap-2024-10-24_10.39.49.mp4
Additionally, when the options have a more complex content, consumers can decide how to deal with content overflow.
TODO
right
listboxes render properly.title
to items that get cropped.listboxOverflow
prop. -> Document theSelect
componentlistboxOverflow
#1754EDIT The missing points there ☝🏼 will be addressed separately to easy reviews.