Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
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
25 changes: 20 additions & 5 deletions src/custom/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface SearchBarProps {
expanded: boolean;
setExpanded: (expanded: boolean) => void;
'data-testid'?: string;
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
}

function SearchBar({
Expand All @@ -83,7 +84,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 @@ -129,15 +131,27 @@ function SearchBar({
}
};


const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {

if (onKeyDown) {
onKeyDown(event);
}


if (event.key === 'Enter') {
onSearch(searchText);
}
};
Comment thread
AasthathecoderX marked this conversation as resolved.
Outdated

return (
<ClickAwayListener
onClickAway={(event) => {
event.stopPropagation();
const isTable = (event.target as HTMLElement)?.closest('#ref');

if (searchText !== '') {
return;
}
if (searchText !== '') return;

if (isTable) {
handleClearIconClick(event as unknown as React.MouseEvent);
}
Expand All @@ -148,10 +162,11 @@ function SearchBar({
<TextField
variant="standard"
value={searchText}
onChange={handleSearchChange} // Updated to use the new handler
onChange={handleSearchChange}// Updated to use the new handler
Comment thread
Rajesh-Nagarajan-11 marked this conversation as resolved.
Outdated
inputRef={searchRef}
placeholder={placeholder}
data-testid="searchbar-input"
onKeyDown={handleKeyDown}
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 @@ -86,20 +89,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>}
/>

Comment thread
Rajesh-Nagarajan-11 marked this conversation as resolved.
Outdated
);
}

Expand Down
Loading