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
feat(Label): truncate by default #8771
feat(Label): truncate by default #8771
Conversation
Preview: https://patternfly-react-pr-8771.surge.sh A11y report: https://patternfly-react-pr-8771-a11y.surge.sh |
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.
Discussed offline, but left a comment about
- removing
isTruncated
- adding a prop for a custom truncation length
Also these conditionals should no longer be needed. We can just include the top block - the span.pf-c-label__text
wrapping {children}
patternfly-react/packages/react-core/src/components/Label/Label.tsx
Lines 211 to 216 in 40e7ec3
{isTruncated && ( | |
<span ref={textRef} className={css(styles.labelText)}> | |
{children} | |
</span> | |
)} | |
{!isTruncated && children} |
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 of test updates that I didn't catch before, otherwise LGTM!
packages/react-core/src/components/Label/__tests__/Label.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/Label/__tests__/Label.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/Label/__tests__/Label.test.tsx
Outdated
Show resolved
Hide resolved
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.
is there no default value for the --pf-c-label__text--MaxWidth
variable? this PR is named 'truncate by default' but if it needs textMaxWidth
prop, then it's not default?
@nicolethoen - i believe it could still truncate due to other constraints limiting the size. @mcoker thoughts? |
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.
@mcarrano - there is another PR to address label/chip restructure, i could rebase this after that one is merged in |
@mcarrano bc the global reset (which was removed) adds |
@mcarrano @mattnolting - here's the PR for that: #8773 i'll rebase this on that once it gets merged. |
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.
Other than a non-blocker below and other comments that have been left, only other thing is whether it'd be worth adding a label to show the default truncation without textMaxWidth
passed in. That also isn't a blocker, though.
Correct, it will truncate by default now when it runs out of space in its container. Setting the textMaxWidth prop allows for a custom width. |
026d986
to
10ce0f8
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.
This looks good now. I agree with @thatblindgeye that it would be nice to have an example that explicitly shows the effect of adding a maxWidth, but not a blocker.
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.
one small nit on a test
@@ -86,7 +86,7 @@ describe('Label', () => { | |||
|
|||
test('label with truncation', () => { | |||
const { asFragment } = render( | |||
<Label isTruncated>Something very very very very very long that should be truncated</Label> | |||
<Label textMaxWidth="16c">textMaxWidth set at 16h on this very long label that should be truncated</Label> |
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.
<Label textMaxWidth="16c">textMaxWidth set at 16h on this very long label that should be truncated</Label> | |
<Label textMaxWidth="16ch">textMaxWidth set at 16ch on this very long label that should be truncated</Label> |
@@ -90,7 +90,7 @@ export const Label: React.FunctionComponent<LabelProps> = ({ | |||
isCompact = false, | |||
isEditable = false, | |||
editableProps, | |||
isTruncated = false, | |||
textMaxWidth = '', |
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.
Should this be undefined?
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.
well line 218 is a falsy check, but i don't see why we couldn't just let this be undefined
@mcarrano @thatblindgeye - sorry i must have missed that comment, added an example of a parent-constrained label https://patternfly-react-pr-8771.surge.sh/components/label/ |
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.
LGTM
Your changes have been released in:
Thanks for your contribution! 🎉 |
What: Closes #8258
Labels: https://patternfly-react-pr-8771.surge.sh/components/label