-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
UI: Fix TreeNode alignment when using a different font #22221
Merged
ndelangen
merged 6 commits into
storybookjs:next
from
bdriguesdev:fix/tree-node-alignment
Sep 14, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
645c7cd
fix: adjust tree node alignment when using a different font
bdriguesdev f562120
refactor: change FunctionComponent for FC to type components
bdriguesdev 222e687
Merge branch 'next' into fix/tree-node-alignment
ndelangen 1de752e
refactor: format file
bdriguesdev 2bc038b
Merge branch 'next' into fix/tree-node-alignment
cdedreuille 0978fdc
Merge branch 'next' into fix/tree-node-alignment
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 do you need this InvisibleText? It should automatically center it in the middle without this line, no?
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 reason is that when the text for the TreeNode breaks in multiple lines the icon needs to be centered with the first line of text on the right side not with the whole container, like the first example here:
To achieve this the only way I found is to wrap the Icon within an element that has a height of just one line of text and align the icon vertically inside it, so it will be aligned with the first line of text of the TreeNode. We can't use a fixed value that represents the height of one line of text because each font can have a different height, to deal with it I used this trick of placing an invisible character to set a height for the container of the icon to be exactly the same as one line of a text.
Makes sense?
Also, we could align the icon in the center of the TreeNode not with the first line of text, that will be way easier and we can remove the InvisibleText
Just for visualization
Aligning with the first line of text:
Aligning with the TreeNode: