3
3
* and hosts it in the component. When the component is selected, it
4
4
* drops-down the contentComponent and applies the contentProps.
5
5
*/
6
- import useOutsideClick from "@rooks/use-outside-click" ;
7
6
import { css } from "goober" ;
8
- import React , { useRef , useState , useEffect } from "react" ;
7
+ import React , { useEffect , useRef , useState } from "react" ;
9
8
10
9
import Arrow from "./arrow" ;
11
10
import Loading from "./loading" ;
@@ -31,41 +30,38 @@ const PanelContainer = css({
31
30
".panel-content" : {
32
31
maxHeight : "300px" ,
33
32
overflowY : "auto" ,
34
- borderRadius : "var(--rmsc-border-radius)" ,
35
- backgroundColor : "var(--rmsc-background)" ,
36
- boxShadow :
37
- "0 0 0 1px hsla(0, 0%, 0%, 0.1), 0 4px 11px hsla(0, 0%, 0%, 0.1)" ,
33
+ borderRadius : "var(--rmsc-radius)" ,
34
+ background : "var(--rmsc-bg)" ,
35
+ boxShadow : "0 0 0 1px rgba(0, 0, 0, 0.1), 0 4px 11px rgba(0, 0, 0, 0.1)" ,
38
36
} ,
39
37
} ) ;
40
38
41
39
const DropdownContainer = css ( {
42
40
position : "relative" ,
43
- outline : "none" ,
44
- backgroundColor : "var(--rmsc-background )" ,
41
+ outline : 0 ,
42
+ backgroundColor : "var(--rmsc-bg )" ,
45
43
border : "1px solid var(--rmsc-border)" ,
46
- borderRadius : "var(--rmsc-border- radius)" ,
44
+ borderRadius : "var(--rmsc-radius)" ,
47
45
"&:focus-within" : {
48
- boxShadow : "var(--rmsc-primary) 0px 0px 0px 1px" ,
49
- borderColor : "var(--rmsc-primary )" ,
46
+ boxShadow : "var(--rmsc-main) 0 0 0 1px" ,
47
+ borderColor : "var(--rmsc-main )" ,
50
48
} ,
51
49
} ) ;
52
50
53
51
const DropdownHeading = css ( {
54
52
position : "relative" ,
55
- padding : "0 var(--rmsc-spacing )" ,
53
+ padding : "0 var(--rmsc-p )" ,
56
54
display : "flex" ,
57
55
alignItems : "center" ,
58
- justifyContent : "flex-end" ,
59
- overflow : "hidden" ,
60
56
width : "100%" ,
61
- height : "var(--rmsc-height )" ,
57
+ height : "var(--rmsc-h )" ,
62
58
cursor : "default" ,
63
- outline : "none" ,
59
+ outline : 0 ,
64
60
".dropdown-heading-value" : {
65
61
overflow : "hidden" ,
66
62
textOverflow : "ellipsis" ,
67
63
whiteSpace : "nowrap" ,
68
- flex : "1" ,
64
+ flex : 1 ,
69
65
} ,
70
66
} ) ;
71
67
@@ -86,8 +82,6 @@ const Dropdown = ({
86
82
87
83
const wrapper : any = useRef ( ) ;
88
84
89
- useOutsideClick ( wrapper , ( ) => setExpanded ( false ) ) ;
90
-
91
85
/* eslint-disable react-hooks/exhaustive-deps */
92
86
useEffect ( ( ) => {
93
87
onMenuToggle && onMenuToggle ( expanded ) ;
@@ -98,7 +92,9 @@ const Dropdown = ({
98
92
case 27 : // Escape
99
93
case 38 : // Up Arrow
100
94
setExpanded ( false ) ;
95
+ wrapper ?. current ?. focus ( ) ;
101
96
break ;
97
+ case 32 : // Space
102
98
case 13 : // Enter Key
103
99
case 40 : // Down Arrow
104
100
setExpanded ( true ) ;
@@ -108,15 +104,24 @@ const Dropdown = ({
108
104
}
109
105
e . preventDefault ( ) ;
110
106
} ;
107
+
111
108
const handleHover = ( iexpanded : boolean ) => {
112
109
shouldToggleOnHover && setExpanded ( iexpanded ) ;
113
110
} ;
114
- const handleFocus = ( e ) => {
115
- e . target === wrapper && ! hasFocus && setHasFocus ( true ) ;
111
+
112
+ const handleFocus = ( ) => ! hasFocus && setHasFocus ( true ) ;
113
+
114
+ const handleBlur = ( e ) => {
115
+ if ( ! e . relatedTarget ) {
116
+ setHasFocus ( false ) ;
117
+ setExpanded ( false ) ;
118
+ }
116
119
} ;
117
- const handleBlur = ( ) => hasFocus && setHasFocus ( false ) ;
120
+
118
121
const handleMouseEnter = ( ) => handleHover ( true ) ;
122
+
119
123
const handleMouseLeave = ( ) => handleHover ( false ) ;
124
+
120
125
const toggleExpanded = ( ) =>
121
126
setExpanded ( isLoading || disabled ? false : ! expanded ) ;
122
127
@@ -126,7 +131,7 @@ const Dropdown = ({
126
131
className = { `${ DropdownContainer } dropdown-container` }
127
132
aria-labelledby = { labelledBy }
128
133
aria-expanded = { expanded }
129
- aria-readonly = " true"
134
+ aria-readonly = { true }
130
135
aria-disabled = { disabled }
131
136
ref = { wrapper }
132
137
onKeyDown = { handleKeyDown }
0 commit comments