Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/custom/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface SearchBarProps {
expanded: boolean;
setExpanded: (expanded: boolean) => void;
'data-testid'?: string;
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
}

function SearchBar({
Expand All @@ -84,7 +85,8 @@ function SearchBar({
onClear,
expanded,
setExpanded,
'data-testid': testId = 'search-bar-wrapper'
'data-testid': testId = 'search-bar-wrapper',
onKeyDown
}: SearchBarProps): JSX.Element {
const [searchText, setSearchText] = React.useState('');
const searchRef = React.useRef<HTMLInputElement | null>(null);
Expand Down Expand Up @@ -149,10 +151,11 @@ function SearchBar({
<TextField
variant="standard"
value={searchText}
onChange={handleSearchChange} // Updated to use the new handler
onChange={handleSearchChange}
inputRef={searchRef}
placeholder={placeholder}
data-testid="searchbar-input"
onKeyDown={onKeyDown}
style={{
width: expanded ? '150px' : '0',
opacity: expanded ? 1 : 0,
Expand Down
35 changes: 20 additions & 15 deletions src/custom/StyledSearchBar/StyledSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface SearchBarProps {
sx?: SxProps<Theme>;
endAdornment?: React.ReactNode;
debounceTime?: number;
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
}

/**
Expand All @@ -38,8 +39,10 @@ function StyledSearchBar({
sx,
placeholder,
endAdornment,
debounceTime = 300
debounceTime = 300,
onKeyDown
}: SearchBarProps): JSX.Element {

const theme = useTheme();
const [inputValue, setInputValue] = useState(value);

Expand Down Expand Up @@ -87,20 +90,22 @@ function StyledSearchBar({

return (
<StyledSearchInput
type="search"
label={label}
fullWidth
value={inputValue}
onChange={handleChange}
sx={sx}
placeholder={placeholder ?? 'Search'}
startAdornment={
<InputAdornment position="start">
<SearchIcon fill={theme.palette.background.neutral?.default} />
</InputAdornment>
}
endAdornment={<InputAdornmentEnd position="end">{endAdornment}</InputAdornmentEnd>}
/>
type="search"
label={label}
fullWidth
value={inputValue}
onChange={handleChange}
sx={sx}
placeholder={placeholder ?? 'Search'}
onKeyDown={onKeyDown}
startAdornment={
<InputAdornment position="start">
<SearchIcon fill={theme.palette.background.neutral?.default} />
</InputAdornment>
}
endAdornment={<InputAdornmentEnd position="end">{endAdornment}</InputAdornmentEnd>}
/>

);
}

Expand Down
Loading