diff --git a/packages/ra-ui-materialui/src/input/ResettableTextField.js b/packages/ra-ui-materialui/src/input/ResettableTextField.js index d6ad093f0b0..2e6a552c0b7 100644 --- a/packages/ra-ui-materialui/src/input/ResettableTextField.js +++ b/packages/ra-ui-materialui/src/input/ResettableTextField.js @@ -1,4 +1,4 @@ -import React, { useState, useCallback } from 'react'; +import React, { useCallback } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import InputAdornment from '@material-ui/core/InputAdornment'; @@ -18,11 +18,8 @@ const useStyles = makeStyles({ }, clearButton: { height: 24, - padding: 0, - width: 0, - }, - visibleClearButton: { width: 24, + padding: 0, }, selectAdornment: { position: 'absolute', @@ -51,7 +48,6 @@ function ResettableTextField({ margin = 'dense', ...props }) { - const [showClear, setShowClear] = useState(false); const classes = useStyles({ classes: classesOverride }); const translate = useTranslate(); @@ -66,7 +62,6 @@ function ResettableTextField({ const handleFocus = useCallback( event => { - setShowClear(true); onFocus && onFocus(event); }, [onFocus] @@ -74,7 +69,6 @@ function ResettableTextField({ const handleBlur = useCallback( event => { - setShowClear(false); onBlur && onBlur(event); }, [onBlur] @@ -90,16 +84,21 @@ function ResettableTextField({ ...restClasses } = classes; - return ( - { + if (!resettable) { + return endAdornment; + } else if (!value) { + if (clearAlwaysVisible) { + // show clear button, inactive + return ( - ), - ...InputProps, + ); + } else { + if (endAdornment) { + return endAdornment; + } else { + // show spacer + return ( + +   + + ); + } + } + } else { + // show clear + return ( + + + + + + ); + } + }; + + return ( +