File tree 3 files changed +18
-6
lines changed
example/stories/dynamic-suggestions-list
3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,6 @@ Whether you want to showcase a constant list of options or dynamically adapt to
26
26
27
27
- autoFocus
28
28
29
- - Open Suggestion List on Enter Key
30
-
31
29
## Installation
32
30
33
31
> $ npm install react-custom-search-list @popperjs/core --save
@@ -92,6 +90,14 @@ function App() {
92
90
- ** children**
93
91
- type : ` ReactNode `
94
92
- description : suggestions list
93
+ - ** openOnClick?**
94
+ - type :` Boolean `
95
+ - description : if it is true then the suggestion list will be open when the user clicks on the input
96
+ - default : ` True `
97
+ - ** openOnKeyDown?**
98
+ - type : ` (e) => Boolean `
99
+ - description : if it returns true then the suggestion list will be open
100
+ - default : ` (e) => e.key === "Enter" `
95
101
- ** rootStyle?**
96
102
- type : ` Object `
97
103
- description : style object of the ` root ` element
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ function App() {
16
16
value= {value}
17
17
onChange= {(e ) => setValue (e .target .value )}
18
18
onClear= {() => setValue (' ' )}
19
+ openOnKeyDown= {() => true }
20
+ autoFocus= {true }
19
21
fullWidth
20
22
theme= " outline"
21
23
corner>
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ import ClearIcon from './icons/clear.js';
25
25
* @param {Boolean } [props.corner=true] - if set true then border-radius would be "5px"
26
26
* @param {Boolean } [props.autoFocus=false] - autoFocus attribute for the input element
27
27
* @param {String } [props.inputName=""] - name attribute for the input element
28
+ * @param {Boolean } [props.openOnClick=true] - if it is true then the suggestion list will be open when the user clicks on the input
29
+ * @param {(e)=>Boolean } [props.openOnKeyDown=(e)=>e.key === 'Enter'] -it it returns true then the suggestion list will be open
28
30
*/
29
31
function ReactCustomSearchList ( props ) {
30
32
const {
@@ -48,20 +50,22 @@ function ReactCustomSearchList(props) {
48
50
corner = true ,
49
51
autoFocus = false ,
50
52
inputName = '' ,
53
+ openOnClick = true ,
54
+ openOnKeyDown = ( e ) => e . key === 'Enter' || e . keyCode === 13 ,
51
55
} = props ;
52
56
const [ open , setOpen ] = useState ( false ) ;
53
57
const rootRef = useRef ( ) ;
54
58
const onClickHandler = useCallback ( ( ) => {
55
- setOpen ( true ) ;
56
- } , [ ] ) ;
59
+ openOnClick && setOpen ( true ) ;
60
+ } , [ openOnClick ] ) ;
57
61
const onKeyDownHandler = useCallback (
58
62
( e ) => {
59
- if ( e . key === 'Enter' || e . keyCode === 13 ) {
63
+ if ( openOnKeyDown ( e ) == true ) {
60
64
setOpen ( true ) ;
61
65
}
62
66
onKeyDown ( e ) ;
63
67
} ,
64
- [ onKeyDown ] ,
68
+ [ onKeyDown , openOnKeyDown ] ,
65
69
) ;
66
70
useEffect ( ( ) => {
67
71
const rEl = document . documentElement ,
You can’t perform that action at this time.
0 commit comments