-
Notifications
You must be signed in to change notification settings - Fork 1
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
Dynamically truncate text to be the right length for the StyledSelect box #55
Dynamically truncate text to be the right length for the StyledSelect box #55
Conversation
@@ -1,5 +1,4 @@ | |||
import { describe, test, expect } from 'vitest' | |||
import { act, fireEvent } from '@testing-library/react' |
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.
These weren't being used.
type MouseEventHandler, | ||
type CSSProperties, | ||
} from 'react' | ||
import { useState, useEffect, type CSSProperties } from 'react' |
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 removed imports were not being used.
const truncatedText = (text: string, width?: number) => { | ||
if (!width) return | ||
|
||
const maxWidth = width - 48 |
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.
48: width of button + side margins
7413014
to
e553138
Compare
Context
Fix whatever is going on with StyledSelect
The
StyledSelect
component currently truncates text to a fixed length of 24 characters to enable it to fit inside. However, we realised that when the text inside contains wide characters, 24 characters is too long. Additionally, at some viewport widths, 24 characters isn't long enough to fill theStyledSelect
component's width and looks weird with the text truncated that short. We needed a way to dynamically truncate text to the correct length depending on the size of the component.Changes
StyledSelect
componentRequired Tasks
Add/update Storybook storiesAdd/update docsConsiderations
Unfortunately, dynamically sizing the text makes the functionality significantly less testable due to the fact that it makes use of
canvas
. While thenode-canvas
package enablescanvas
to be used in Node environments, the package doesn't support worker_threads, which our testing setup apparently requires. The maintainers have indicated they would like to add this support this year, so instead of deleting the tests that no longer work, I've marked them to be skipped so we can come back to them once a new versionnode-canvas
comes out that provides the support we need.Manual Test Cases
You can test this by following the repro steps present on the Trello card and seeing that the bug doesn't occur:
You'll want to test this at multiple viewport widths, paying particular attention to viewport widths between 320px and 480px, inclusive, since at these widths the size of the
StyledSelect
component changes with the viewport.You'll also want to ensure that selecting games still works, etc.
Screenshots and GIFs
Screenshots up to 769px are shown. Even this is really overkill because the size of the dropdown is static for viewport widths above 481px.
320px
320px
480px
481px
601px
769px