-
Notifications
You must be signed in to change notification settings - Fork 45
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
Tag
- Text truncation for overflow fix
#2655
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 is looking great, although I did find an interesting "bug"
The tooltip is still there even if the text is fully revealed. Wonder if there is a way to fix this?
UPDATE: It looks like something that was once truncated, but then isn't will have a tooltip. We should also check screen reader behavior. Does the text get read out twice or just once? I think we can loop in the entire team for A11Y
Def want to call out that the there needs to be documentation that informs consumers that truncated text is not accessible for all users and they should prefer limiting the text length before the need for truncation exists. |
Can you elaborate on this? Truncated text will always have tooltips associated to it. Also from my understanding, truncation is a CSS based visual indicator that should still be accessible by a screen reader. One call out is to make sure that the text isn't read out twice. Is there something else I'm missing? |
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.
Left one suggestion – otherwise looking great!
@tracked private _isTextOverflow!: boolean; | ||
private _observer!: ResizeObserver; | ||
|
||
private _setUpObserver = modifier((element: HTMLElement) => { |
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 like how this aligns with the AdvancedTable observer!
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.
all credit to dylan, I followed his pattern :)
@@ -104,4 +125,8 @@ export default class HdsTag extends Component<HdsTagSignature> { | |||
|
|||
return classes.join(' '); | |||
} | |||
|
|||
private _isOverflow(el: Element): boolean { | |||
return el.scrollHeight > el.clientHeight; |
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.
🙌
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.
Just a couple small suggestions, looks good!
📌 Summary
This PR fixes an overflow issue present in the
Tag
when text wraps to > 3 lines. It implements the intended design change to address this, which truncates any text that goes to multiple lines. When truncation occurs, an ellipsis is rendered, and a tooltip showing the full text is added.It also adds
width: fit-content;
to the tag to ensure a tag's width never goes beyond its content.🛠️ Detailed description
It was observed in the Tag in HDS-3854 that when the text exceeds 3 lines, the background of the dismiss button obscures the border of the element.
Per design guidance, the chosen solution has been to truncate any text in the tag that goes beyond one line, and add an ellipsis and tooltip with the full text when this truncation occurs.
The text is truncated when the text would wrap to multiple lines using
overflow: hidden
and-webkit-line-clamp: 1
. When this occurs a tooltip is also added using thehds-tooltip
modifier, and theHds::TooltipButton
.There are several other changes related to this fix.
max-width
of the text is set to150px
@tooltipPlacement
has been added to allow for customization of the tooltip placementwidth: fit-content
has been added to prevent the tag width from ever exceeding its content. This was present previously when the tag had a parent withdisplay: grid
.📸 Screenshots
Text Truncation
Before
![Screenshot 2025-01-24 at 9 24 43 AM](https://private-user-images.githubusercontent.com/28073391/406471165-2541acbd-7b2a-402a-99f7-373fcaa276ce.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTcyMzIsIm5iZiI6MTczOTM1NjkzMiwicGF0aCI6Ii8yODA3MzM5MS80MDY0NzExNjUtMjU0MWFjYmQtN2IyYS00MDJhLTk5ZjctMzczZmNhYTI3NmNlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDEwNDIxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE0Njg1NDg2ZWYwZTBhNDgwNzljODM3MjE0Y2YxMDM3ZjY4NDM1M2Y1NmRmMjNhOWU1NjViZDY3ZjA1MWU4OTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.2gY_sfdeMATho0lW-2Yniv1vN15PE8z-M8r3no3dmp4)
After
![Screenshot 2025-02-10 at 4 27 06 PM](https://private-user-images.githubusercontent.com/28073391/411748725-8a9b905c-1b4d-4085-89dd-0ab3ee5fa2ec.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTcyMzIsIm5iZiI6MTczOTM1NjkzMiwicGF0aCI6Ii8yODA3MzM5MS80MTE3NDg3MjUtOGE5YjkwNWMtMWI0ZC00MDg1LTg5ZGQtMGFiM2VlNWZhMmVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDEwNDIxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZjMjA3MGU5YjE3NjFkM2Q4MWFkMDRhZDY1ODU5NzY3OWE2NGMwYTFlMjBjZTYyYzM4NzdmNzZmZGExOGVhM2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.jzEGp8lPJAWsjFN4M36QXCrt2fdD2LqLkXyeJz95gOU)
After - Hover / Focus
![Screenshot 2025-02-10 at 4 25 52 PM](https://private-user-images.githubusercontent.com/28073391/411748478-962d5636-0686-4bff-90ad-86d3d9d49514.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTcyMzIsIm5iZiI6MTczOTM1NjkzMiwicGF0aCI6Ii8yODA3MzM5MS80MTE3NDg0NzgtOTYyZDU2MzYtMDY4Ni00YmZmLTkwYWQtODZkM2Q5ZDQ5NTE0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDEwNDIxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg0NDM3ZWMyYzkyOWQ3MTUzZDVhOTk3NTIxYjMzYmRmMGY2ZDVhZTFiYzY0N2RkN2IxYmQyMzJjNGE3NzI1Y2YmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.r5273fpLrJORLuUu3q6KrOaa-RWCZF-DkkmF2shXims)
Width
Before
![Screenshot 2025-02-05 at 9 28 22 AM](https://private-user-images.githubusercontent.com/28073391/410034104-048d71c2-98ae-4fde-a1ce-94c2f6d0374b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTcyMzIsIm5iZiI6MTczOTM1NjkzMiwicGF0aCI6Ii8yODA3MzM5MS80MTAwMzQxMDQtMDQ4ZDcxYzItOThhZS00ZmRlLWExY2UtOTRjMmY2ZDAzNzRiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDEwNDIxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTMzZTlkY2FjZDAyOTE3MzYyNmI5NmQwNWNlNGI5ZjgxZWVjZGJmMmVhYmNmZjBlYjE1NzY4ZGRjZDA2NGZhNDYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.1Gr8fYQLOXhGVYIVKwTuoJL_d3lu_RgKlsZQisibQ84)
After
![Screenshot 2025-02-10 at 4 26 07 PM](https://private-user-images.githubusercontent.com/28073391/411748552-8ed56b31-4e5a-405a-adde-e6d3740d2da5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTcyMzIsIm5iZiI6MTczOTM1NjkzMiwicGF0aCI6Ii8yODA3MzM5MS80MTE3NDg1NTItOGVkNTZiMzEtNGU1YS00MDVhLWFkZGUtZTZkMzc0MGQyZGE1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDEwNDIxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE3MDdiZWUxODM3OTkyYTgwYzFmNGFkNmQ5ODQzYzIwMTcxNzEwNTVkZGYyMDQ5MGU5YTNmYzNhMDY0OTA5MWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.jTLnxDXoO-BBVtzouF7DErfn8r4GRdjKve2wszQyiOg)
🔗 External links
Jira ticket: HDS-4317
Figma file: Link
👀 Component checklist
💬 Please consider using conventional comments when reviewing this PR.