-
Notifications
You must be signed in to change notification settings - Fork 63
fix: pill visibility on small screens #991
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,18 +14,37 @@ export const useMaxVisibleSections = ( | |||||||||||||||||||||||||||||||||||||||||||||
width: 0, | ||||||||||||||||||||||||||||||||||||||||||||||
count: 0, | ||||||||||||||||||||||||||||||||||||||||||||||
filled: false, | ||||||||||||||||||||||||||||||||||||||||||||||
maxPillWidth: 144, | ||||||||||||||||||||||||||||||||||||||||||||||
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. 1 Define an interface for the maxSections object shape to improve type safety and maintainability: interface MaxSections {
readonly width: number;
readonly count: number;
readonly filled: boolean;
readonly maxPillWidth: number;
} Then use this interface consistently: const [maxSections, setMaxSections] = useState<MaxSections>({...}); Footnotes
|
||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const computeVisibleSections = () => { | ||||||||||||||||||||||||||||||||||||||||||||||
const selectedItemsLength = itemsRef.current?.filter(Boolean)?.length; | ||||||||||||||||||||||||||||||||||||||||||||||
if (selectedItemsLength === 0) return; | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+21
to
+22
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. 1 Early return should maintain consistent object shape to prevent runtime errors: if (selectedItemsLength === 0) {
return {
width: 0,
count: 0,
filled: false,
maxPillWidth: 144
};
} Committable suggestion
Suggested change
Footnotes
Comment on lines
+21
to
+22
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. 1 Return consistent object shape when no items are selected: if (selectedItemsLength === 0) {
return {
width: 0,
count: 0,
filled: false,
maxPillWidth: 144
};
} Committable suggestion
Suggested change
Footnotes
|
||||||||||||||||||||||||||||||||||||||||||||||
const containerWidth = | ||||||||||||||||||||||||||||||||||||||||||||||
containerRef.current?.getBoundingClientRect().width ?? 0; | ||||||||||||||||||||||||||||||||||||||||||||||
const firstItemWidth = | ||||||||||||||||||||||||||||||||||||||||||||||
itemsRef.current?.[0]?.getBoundingClientRect().width ?? extraItemWidth; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const isSingleItem = selectedItemsLength === 1; | ||||||||||||||||||||||||||||||||||||||||||||||
const isNarrowContainer = isSingleItem | ||||||||||||||||||||||||||||||||||||||||||||||
? containerWidth <= 210 | ||||||||||||||||||||||||||||||||||||||||||||||
: containerWidth <= 350; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const updatedExtraItemWidth = isSingleItem | ||||||||||||||||||||||||||||||||||||||||||||||
? 40 | ||||||||||||||||||||||||||||||||||||||||||||||
: isNarrowContainer | ||||||||||||||||||||||||||||||||||||||||||||||
? containerWidth * 0.45 | ||||||||||||||||||||||||||||||||||||||||||||||
: firstItemWidth + 24; | ||||||||||||||||||||||||||||||||||||||||||||||
const maxPillWidth = isNarrowContainer ? 100 : 144; | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+23
to
+38
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. is this possible without doing a boundingClientRect call |
||||||||||||||||||||||||||||||||||||||||||||||
const availableWidth: number = | ||||||||||||||||||||||||||||||||||||||||||||||
(containerRef.current?.getBoundingClientRect().width - extraItemWidth) * | ||||||||||||||||||||||||||||||||||||||||||||||
linesToShow; | ||||||||||||||||||||||||||||||||||||||||||||||
(containerWidth - updatedExtraItemWidth) * linesToShow; | ||||||||||||||||||||||||||||||||||||||||||||||
const sections = itemsRef.current?.reduce( | ||||||||||||||||||||||||||||||||||||||||||||||
( | ||||||||||||||||||||||||||||||||||||||||||||||
acc: { | ||||||||||||||||||||||||||||||||||||||||||||||
width: number; | ||||||||||||||||||||||||||||||||||||||||||||||
count: number; | ||||||||||||||||||||||||||||||||||||||||||||||
filled: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||
maxPillWidth: number; | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
ref: HTMLElement | ||||||||||||||||||||||||||||||||||||||||||||||
) => { | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -45,6 +64,7 @@ export const useMaxVisibleSections = ( | |||||||||||||||||||||||||||||||||||||||||||||
width: 0, | ||||||||||||||||||||||||||||||||||||||||||||||
count: 0, | ||||||||||||||||||||||||||||||||||||||||||||||
filled: false, | ||||||||||||||||||||||||||||||||||||||||||||||
maxPillWidth: maxPillWidth, | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||
setMaxSections(sections); | ||||||||||||||||||||||||||||||||||||||||||||||
|
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.
why maxPillWidth, just pillWidth