Skip to content

Commit

Permalink
[InputBase] Declare global mui-auto-fill(-cancel) keyframes
Browse files Browse the repository at this point in the history
Browser autofill workaround logic requires static animation name references for
keyframes. Enabling disableGlobal renames such keyframes unless they are marked
as global.
  • Loading branch information
Martin Jesper Low Madsen committed Jan 31, 2020
1 parent ac5c1ae commit 332b6c8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/material-ui/src/InputBase/InputBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export const styles = theme => {
};

return {
'@global': {
'@keyframes mui-auto-fill': {
from: {},
},
'@keyframes mui-auto-fill-cancel': {
from: {},
},
},
/* Styles applied to the root element. */
root: {
// Mimics the default input display property used by browsers for an input.
Expand Down Expand Up @@ -87,7 +95,7 @@ export const styles = theme => {
// Make the flex item shrink with Firefox
minWidth: 0,
width: '100%', // Fix IE 11 width issue
animationName: '$auto-fill-cancel',
animationName: 'mui-auto-fill-cancel',
'&::-webkit-input-placeholder': placeholder,
'&::-moz-placeholder': placeholder, // Firefox 19+
'&:-ms-input-placeholder': placeholder, // IE 11
Expand Down Expand Up @@ -119,15 +127,9 @@ export const styles = theme => {
},
'&:-webkit-autofill': {
animationDuration: '5000s',
animationName: '$auto-fill',
animationName: 'mui-auto-fill',
},
},
'@keyframes auto-fill': {
from: {},
},
'@keyframes auto-fill-cancel': {
from: {},
},
/* Styles applied to the `input` element if `margin="dense"`. */
inputMarginDense: {
paddingTop: 4 - 1,
Expand Down Expand Up @@ -387,9 +389,7 @@ const InputBase = React.forwardRef(function InputBase(props, ref) {

const handleAutoFill = event => {
// Provide a fake value as Chrome might not let you access it for security reasons.
checkDirty(
event.animationName.indexOf('auto-fill-cancel') !== -1 ? inputRef.current : { value: 'x' },
);
checkDirty(event.animationName === 'mui-auto-fill-cancel' ? inputRef.current : { value: 'x' });
};

React.useEffect(() => {
Expand Down

0 comments on commit 332b6c8

Please sign in to comment.