Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display label in autocomplete filter text input, not value #972

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,6 +30,7 @@ import {
type TimePickerProps,
} from '@mui/x-date-pickers/TimePicker';
import {
type DropdownOption,
type MRT_Header,
type MRT_RowData,
type MRT_TableInstance,
Expand Down Expand Up @@ -433,37 +434,41 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
},
}}
/>
) : isAutocompleteFilter ? (
<Autocomplete
freeSolo
getOptionLabel={(option) => getValueAndLabel(option).label}
onChange={(_e, newValue) =>
handleChange(getValueAndLabel(newValue).value)
}
options={
dropdownOptions?.map((option) => getValueAndLabel(option)) ?? []
}
{...autocompleteProps}
renderInput={(builtinTextFieldProps) => (
<TextField
{...builtinTextFieldProps}
{...commonTextFieldProps}
InputProps={{
...builtinTextFieldProps.InputProps,
startAdornment:
) : isAutocompleteFilter ? (() => {
const [autocompleteValue, setAutocompleteValue] = useState<DropdownOption | null>(null);
const handleAutocompleteChange = (newValue: DropdownOption) => {
setAutocompleteValue(newValue);
handleChange(getValueAndLabel(newValue).value);
};
return <Autocomplete
freeSolo
getOptionLabel={(option) => getValueAndLabel(option).label}
onChange={(_e, newValue) => handleAutocompleteChange(newValue)}
options={
dropdownOptions?.map((option) => getValueAndLabel(option)) ?? []
}
{...autocompleteProps}
renderInput={(builtinTextFieldProps) => (
<TextField
{...builtinTextFieldProps}
{...commonTextFieldProps}
InputProps={{
...builtinTextFieldProps.InputProps,
startAdornment:
commonTextFieldProps?.InputProps?.startAdornment,
}}
inputProps={{
...builtinTextFieldProps.inputProps,
...commonTextFieldProps?.inputProps,
}}
onChange={handleTextFieldChange}
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
/>
)}
value={filterValue}
/>
) : (
}}
inputProps={{
...builtinTextFieldProps.inputProps,
...commonTextFieldProps?.inputProps,
}}
onChange={handleTextFieldChange}
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
/>
)}
value={autocompleteValue}
/>;
}
)() : (
<TextField
select={isSelectFilter || isMultiSelectFilter}
{...commonTextFieldProps}
Expand Down