forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchInputWithNavigableOptions.tsx
More file actions
44 lines (38 loc) · 1.28 KB
/
SearchInputWithNavigableOptions.tsx
File metadata and controls
44 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { useState } from 'react';
import { SearchInput } from '@patternfly/react-core';
export const SearchInputWithNavigableOptions: React.FunctionComponent = () => {
const [value, setValue] = useState('');
const [resultsCount, setResultsCount] = useState(0);
const [currentResult, setCurrentResult] = useState(1);
const onChange = (value: string) => {
setValue(value);
setResultsCount(3);
};
const onClear = () => {
setValue('');
setResultsCount(0);
setCurrentResult(1);
};
const onNext = () => {
const newCurrentResult = currentResult + 1;
setCurrentResult(newCurrentResult > resultsCount ? resultsCount : newCurrentResult);
};
const onPrevious = () => {
const newCurrentResult = currentResult - 1;
setCurrentResult(newCurrentResult > 0 ? newCurrentResult : 1);
};
return (
<SearchInput
aria-label="Search match with navigable options example"
placeholder="Find by name"
value={value}
onChange={(_event, value) => onChange(value)}
onClear={onClear}
isNextNavigationButtonDisabled={currentResult === 3}
isPreviousNavigationButtonDisabled={currentResult === 1}
resultsCount={`${currentResult} / ${resultsCount}`}
onNextClick={onNext}
onPreviousClick={onPrevious}
/>
);
};