Skip to content

Commit fbccacb

Browse files
committed
[Autocomplete] Pass fullWidth prop to input, with default as true
1 parent b09d704 commit fbccacb

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

packages/mui-material/src/Autocomplete/Autocomplete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) {
677677
{renderInput({
678678
id,
679679
disabled,
680-
fullWidth: true,
680+
fullWidth: props.fullWidth ?? true,
681681
size: size === 'small' ? 'small' : undefined,
682682
InputLabelProps: getInputLabelProps(),
683683
InputProps: {

packages/mui-material/src/Autocomplete/Autocomplete.test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,16 +3019,35 @@ describe('<Autocomplete />', () => {
30193019

30203020
describe('prop: fullWidth', () => {
30213021
it('should have the fullWidth class', () => {
3022-
const view = render(
3022+
const renderInput = spy((params) => <TextField {...params} />);
3023+
const { container, rerender } = render(
3024+
<Autocomplete fullWidth options={[0, 10, 20]} renderInput={renderInput} value={null} />,
3025+
);
3026+
3027+
expect(container.querySelector(`.${classes.root}`)).to.have.class(classes.fullWidth);
3028+
expect(renderInput.lastCall.args[0].fullWidth).to.equal(true);
3029+
3030+
rerender(
30233031
<Autocomplete
3024-
fullWidth
3032+
fullWidth={false}
30253033
options={[0, 10, 20]}
3026-
renderInput={(params) => <TextField {...params} />}
3034+
renderInput={renderInput}
30273035
value={null}
30283036
/>,
30293037
);
30303038

3031-
expect(view.container.querySelector(`.${classes.root}`)).to.have.class(classes.fullWidth);
3039+
expect(container.querySelector(`.${classes.root}`)).not.to.have.class(classes.fullWidth);
3040+
expect(renderInput.lastCall.args[0].fullWidth).to.equal(false);
3041+
});
3042+
3043+
it('should pass fullWidth as true to renderInput if not provided', () => {
3044+
const renderInput = spy((params) => <TextField {...params} />);
3045+
const view = render(
3046+
<Autocomplete options={[0, 10, 20]} renderInput={renderInput} value={null} />,
3047+
);
3048+
3049+
expect(view.container.querySelector(`.${classes.root}`)).not.to.have.class(classes.fullWidth);
3050+
expect(renderInput.lastCall.args[0].fullWidth).to.equal(true);
30323051
});
30333052
});
30343053

0 commit comments

Comments
 (0)