Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/mui-material/src/OutlinedInput/NotchedOutline.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const NotchedOutlineLegend = styled('legend', {
{
props: ({ ownerState }) => ownerState.withLabel && ownerState.notched,
style: {
maxWidth: '100%',
// Safari: avoid percentage max-width on <legend> inside <fieldset> in flex layouts.
maxWidth: 'none',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the now unlimited-width <legend> is visually clipped by it's enclosing <fieldset>, the scroll dimensions of the component is changed and could cause unexpected scrollbars when the layout is narrow:

<Box sx={{ width: 220, overflowX: 'auto' }}>
  <TextField
    label="This label is intentionally too long for the outlined input widt…"
    defaultValue="Hello world"
    variant="outlined"
    sx={{ width: 195 }}
  />
</Box>
Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch and thanks for the feedback. Since this has gone through a few iterations over the last couple of years, I'm going to try to make an adjustment to how we calculate the notch's width using a ResizeObserver similar to select/autocomplete's width calculations. This is less ideal, but follows an established pattern. I hope to have an update within the next day or three.

transition: theme.transitions.create('max-width', {
duration: 100,
easing: theme.transitions.easing.easeOut,
Expand Down
6 changes: 3 additions & 3 deletions packages/mui-material/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,9 @@ describe('<Select />', () => {
</Select>,
);

expect(container.querySelector('legend')).toHaveComputedStyle({
maxWidth: '100%',
});
expect(container.querySelector('legend').getBoundingClientRect().width).to.be.greaterThan(
1,
);
},
);
});
Expand Down
15 changes: 15 additions & 0 deletions packages/mui-material/src/TextField/TextField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FormControl from '@mui/material/FormControl';
import { inputBaseClasses } from '@mui/material/InputBase';
import MenuItem from '@mui/material/MenuItem';
import { outlinedInputClasses } from '@mui/material/OutlinedInput';
import Stack from '@mui/material/Stack';
import TextField, { textFieldClasses as classes } from '@mui/material/TextField';
import describeConformance from '../../test/describeConformance';

Expand Down Expand Up @@ -223,6 +224,20 @@ describe('<TextField />', () => {
});
},
);

it.skipIf(isJsdom())('should expand notch when focused inside a Stack layout', function test() {
const { container } = render(
<Stack spacing={2} sx={{ width: 300 }}>
<TextField label="First name" variant="outlined" />
</Stack>,
);

const input = screen.getByRole('textbox', { name: 'First name' });
fireEvent.focus(input);

const legend = container.querySelector('fieldset legend');
expect(legend.getBoundingClientRect().width).to.be.greaterThan(1);
});
});

describe('prop: InputProps', () => {
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/fixtures/TextField/OutlinedTextFieldInStack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';

export default function OutlinedTextFieldInStack() {
return (
<Stack spacing={2} sx={{ width: 300 }}>
<TextField id="outlined-in-stack" label="First name" variant="outlined" />
</Stack>
);
}
13 changes: 13 additions & 0 deletions test/e2e/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ describe('e2e', () => {
const errorSelector = page.locator('.MuiInputBase-root.Mui-error');
await errorSelector.waitFor();
});

it('should expand the notched outline when focused inside a Stack layout', async () => {
await renderFixture('TextField/OutlinedTextFieldInStack');

const input = page.getByRole('textbox', { name: 'First name' });
await input.click();

const notchWidth = await page
.locator('fieldset legend')
.evaluate((element) => element.getBoundingClientRect().width);

expect(notchWidth).toBeGreaterThan(1);
});
});

describe('<Select />', () => {
Expand Down
Loading