Repository navigation
[fab] Let an extended Fab grow to fit a wrapping label #49529
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
Open
teoarjun
wants to merge
3
commits into
mui:master
Choose a base branch
from
teoarjun:fix/fab-extended-wrapping-label
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−7
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,59 @@ describe('<Fab />', () => { | |
| expect(button).to.have.class(classes.sizeMedium); | ||
| }); | ||
|
|
||
| // JSDOM does no layout, so the one-line heights are only measurable in a real | ||
| // browser. The content is 1.75em tall whatever the font family, so these are | ||
| // the minimums rather than anything font-dependent. | ||
| it.skipIf(isJsdom())('keeps the one-line height of each extended size', () => { | ||
| render( | ||
| <React.Fragment> | ||
| <Fab variant="extended" data-testid="large"> | ||
| Save | ||
| </Fab> | ||
| <Fab variant="extended" size="medium" data-testid="medium"> | ||
| Save | ||
| </Fab> | ||
| <Fab variant="extended" size="small" data-testid="small"> | ||
| Save | ||
| </Fab> | ||
| </React.Fragment>, | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('large').getBoundingClientRect().height).to.equal(48); | ||
| expect(screen.getByTestId('medium').getBoundingClientRect().height).to.equal(40); | ||
| expect(screen.getByTestId('small').getBoundingClientRect().height).to.equal(34); | ||
| }); | ||
|
|
||
| it.skipIf(isJsdom())('does not stretch to fill a flex parent', () => { | ||
| render( | ||
| <div style={{ display: 'flex', height: 160 }}> | ||
| <Fab variant="extended">Save</Fab> | ||
| </div>, | ||
| ); | ||
|
|
||
| expect(screen.getByRole('button').getBoundingClientRect().height).to.equal(48); | ||
| }); | ||
|
|
||
| // JSDOM does no layout, so the overflow this guards against is only visible | ||
| // in a real browser. | ||
| it.skipIf(isJsdom())('keeps a wrapping label inside the extended button', () => { | ||
|
Member
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. This only covers the large size, and no test checks that a one-line label keeps its height. Could you add:
it.skipIf(isJsdom())('is not stretched by a flex parent', () => {
render(
<div style={{ display: 'flex', height: 100 }}>
<Fab variant="extended">Add</Fab>
</div>,
);
expect(screen.getByRole('button').getBoundingClientRect().height).to.equal(48);
}); |
||
| render( | ||
| <div style={{ width: 120 }}> | ||
| <Fab variant="extended"> | ||
| <span data-testid="label">Create new deployment</span> | ||
| </Fab> | ||
| </div>, | ||
| ); | ||
|
|
||
| const fab = screen.getByRole('button').getBoundingClientRect(); | ||
| const label = screen.getByTestId('label').getBoundingClientRect(); | ||
|
|
||
| // The button grew past its one-line height, so the label wrapped. | ||
| expect(fab.height).to.be.greaterThan(48); | ||
| expect(label.top).to.be.at.least(fab.top); | ||
| expect(label.bottom).to.be.at.most(fab.bottom); | ||
| }); | ||
|
|
||
| it('should have a ripple', async () => { | ||
| const { container } = render(<Fab>Fab</Fab>); | ||
| await ripple.startTouch(screen.getByRole('button')); | ||
|
|
||
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.
Breaking change: a smaller
heightcustomization no longer applies.On master the extended variant set
minHeight: 'auto', so a smallerheightfromsx,styleOverrides.extendedor a theme variant took effect. Now thisminHeightwins, and so do the 34 and 40 below for the small and medium sizes:<Fab variant="extended" sx={{ height: 30 }}>: 30 → 48<Fab variant="extended" size="small" sx={{ height: 28 }}>: 28 → 34Custom sizes added through module augmentation are hit hardest. No built-in variant matches them, so they inherit
minHeight: 48andpadding: '8px 16px'. A customxsmallsize withheight: 28renders at 48.Users can fix it by also setting
minHeight, but nothing warns them, so their layouts just change. I don't see a CSS approach that grows with the content and still keeps a smaller explicitheight. So I think this has to be called out as a breaking change, with a changelog entry and a migration note, or held for the next major. Please also update the PR description, which currently says nothing moves.