Skip to content

Commit

Permalink
startAdornment
Browse files Browse the repository at this point in the history
  • Loading branch information
vmilan committed Jun 7, 2024
1 parent 5d127b1 commit 1b8ba66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/react-ui/src/components/molecules/Autocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export type AutocompleteProps<
ChipComponent extends React.ElementType = ChipTypeMap['defaultComponent']
> = MuiAutocompleteProps<Value, Multiple, DisableClearable, FreeSolo, ChipComponent> & {
creatable?: boolean;
newItemTitle?: React.ReactNode | string;
startAdornment?: React.ReactNode;
inputParams?: object;
};

declare const Autocomplete: <
Expand Down
24 changes: 23 additions & 1 deletion packages/react-ui/src/components/molecules/Autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import {
InputAdornment,
MenuItem,
Autocomplete as MuiAutocomplete,
TextField,
createFilterOptions
} from '@mui/material';

Expand All @@ -18,6 +20,8 @@ const Autocomplete = forwardRef(
forcePopupIcon,
filterOptions,
getOptionLabel,
startAdornment,
inputParams,
...otherProps
},
ref
Expand Down Expand Up @@ -65,14 +69,32 @@ const Autocomplete = forwardRef(
renderOption={creatable ? creatableRenderOption : renderOption}
freeSolo={creatable || freeSolo}
forcePopupIcon={creatable || forcePopupIcon}
renderInput={(params) => {
if (startAdornment) {
params.InputProps.startAdornment = (
<InputAdornment position='start'>{startAdornment}</InputAdornment>
);
}
return (
<div ref={params.InputProps.ref}>
<TextField
{...params}
{...inputParams}
InputLabelProps={{ shrink: true }}
/>
</div>
);
}}
/>
);
}
);

Autocomplete.propTypes = {
creatable: PropTypes.bool,
newItemTitle: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
newItemTitle: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
startAdornment: PropTypes.element,
inputParams: PropTypes.object
};

export default Autocomplete;

0 comments on commit 1b8ba66

Please sign in to comment.