Skip to content

Commit

Permalink
Fix ResettableTextField component endAdornment prop not being applied.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvarcas committed Oct 30, 2019
1 parent 9319c00 commit cc8ea82
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions packages/ra-ui-materialui/src/input/ResettableTextField.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback } from 'react';
import React, { Fragment, useState, useCallback } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import InputAdornment from '@material-ui/core/InputAdornment';
Expand Down Expand Up @@ -84,42 +84,54 @@ function ResettableTextField({
...restClasses
} = classes;

const { endAdornment, ...InputPropsWithoutEndAdornment } = InputProps;

return (
<MuiTextField
classes={restClasses}
value={value}
InputProps={{
endAdornment: resettable && value && (
<InputAdornment
position="end"
classes={{
root: props.select ? classes.selectAdornment : null,
}}
>
<IconButton
className={classNames(clearButton, {
[visibleClearButton]:
clearAlwaysVisible || showClear,
})}
aria-label={translate(
'ra.action.clear_input_value'
)}
title={translate('ra.action.clear_input_value')}
disableRipple
onClick={handleClickClearButton}
onMouseDown={handleMouseDownClearButton}
disabled={disabled}
>
<ClearIcon
className={classNames(clearIcon, {
[visibleClearIcon]:
clearAlwaysVisible || showClear,
})}
/>
</IconButton>
</InputAdornment>
),
...InputProps,
endAdornment:
resettable && value ? (
<Fragment>
<InputAdornment
position="end"
classes={{
root: props.select
? classes.selectAdornment
: null,
}}
>
<IconButton
className={classNames(clearButton, {
[visibleClearButton]:
clearAlwaysVisible || showClear,
})}
aria-label={translate(
'ra.action.clear_input_value'
)}
title={translate(
'ra.action.clear_input_value'
)}
disableRipple
onClick={handleClickClearButton}
onMouseDown={handleMouseDownClearButton}
disabled={disabled}
>
<ClearIcon
className={classNames(clearIcon, {
[visibleClearIcon]:
clearAlwaysVisible || showClear,
})}
/>
</IconButton>
</InputAdornment>
{endAdornment}
</Fragment>
) : (
endAdornment
),
...InputPropsWithoutEndAdornment,
}}
disabled={disabled}
variant={variant}
Expand Down

0 comments on commit cc8ea82

Please sign in to comment.