Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongarciah authored Jan 21, 2025
2 parents 1734573 + cb2a191 commit 840b962
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/mui-material/src/FormControl/FormControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ const FormControl = React.forwardRef(function FormControl(inProps, ref) {
};
}

const onFilled = React.useCallback(() => {
setFilled(true);
}, []);

const onEmpty = React.useCallback(() => {
setFilled(false);
}, []);

const childContext = React.useMemo(() => {
return {
adornedStart,
Expand All @@ -208,15 +216,11 @@ const FormControl = React.forwardRef(function FormControl(inProps, ref) {
onBlur: () => {
setFocused(false);
},
onEmpty: () => {
setFilled(false);
},
onFilled: () => {
setFilled(true);
},
onFocus: () => {
setFocused(true);
},
onEmpty,
onFilled,
registerEffect,
required,
variant,
Expand All @@ -231,6 +235,8 @@ const FormControl = React.forwardRef(function FormControl(inProps, ref) {
fullWidth,
hiddenLabel,
registerEffect,
onEmpty,
onFilled,
required,
size,
variant,
Expand Down
24 changes: 24 additions & 0 deletions packages/mui-material/src/TextField/TextField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,28 @@ describe('<TextField />', () => {
expect(getByRole('textbox')).to.have.attribute('data-testid', 'input-element');
});
});

describe('autofill', () => {
it('should be filled after auto fill event', () => {
function AutoFillComponentTest() {
const [value, setValue] = React.useState('');
return (
<TextField
value={value}
onChange={(event) => setValue(event.target.value)}
label="test"
variant="standard"
slotProps={{
htmlInput: { 'data-testid': 'htmlInput' },
inputLabel: { 'data-testid': 'label' },
}}
/>
);
}

const { getByTestId } = render(<AutoFillComponentTest />);
fireEvent.animationStart(getByTestId('htmlInput'), { animationName: 'mui-auto-fill' });
expect(getByTestId('label').getAttribute('data-shrink')).to.equal('true');
});
});
});

0 comments on commit 840b962

Please sign in to comment.