@@ -7,14 +7,13 @@ import React, {
7
7
useState ,
8
8
} from 'react' ;
9
9
import useDropdown from '../../utils/useDropdown' ;
10
- import useOnClickOutside from '../../utils/useClickOutside' ;
11
10
import { Intents } from '../intents' ;
12
11
import Label , { LabelProps } from '../label' ;
13
12
import EditableSelectContainer from './EditableSelectContainer' ;
14
13
import EditableSelectDropdown from './EditableSelectDropdown' ;
15
14
import EditableSelectInfo from './EditableSelectInfo' ;
16
15
import { EditableSelectTypes , ChipsVariants } from './types' ;
17
- import StickyPortal , { CONTENT_ID } from '../sticky-portal/StickyPortal ' ;
16
+ import DropdownWrapper from '../dropdown-wrapper/DropdownWrapper ' ;
18
17
19
18
export interface EditableSelectProps
20
19
extends Omit < LabelProps , 'onChange' | 'children' > {
@@ -64,12 +63,6 @@ const EditableSelect: FC<EditableSelectProps> = ({
64
63
65
64
const [ isOpen , handleToggle , handleClickOutside ] = useDropdown ( false ) ;
66
65
67
- useOnClickOutside < HTMLDivElement > (
68
- handleClickOutside ,
69
- [ containerRef ] ,
70
- [ CONTENT_ID ] ,
71
- ) ;
72
-
73
66
const unselectedOpts = useMemo (
74
67
( ) => options . filter ( ( opt ) => ! value . includes ( opt ) ) ,
75
68
[ options , value ] ,
@@ -100,38 +93,25 @@ const EditableSelect: FC<EditableSelectProps> = ({
100
93
101
94
useEffect ( ( ) => {
102
95
// Reopen dropdrown when typing.
103
- if ( ! isOpen && search !== '' ) {
104
- if ( isMulti || search !== value [ 0 ] ) handleToggle ( ) ;
96
+ if ( ! isOpen && search !== '' && ( isMulti || search !== value [ 0 ] ) ) {
97
+ handleToggle ( ) ;
105
98
}
99
+ // eslint-disable-next-line react-hooks/exhaustive-deps
106
100
} , [ search ] ) ;
107
101
108
102
const dropdrownWidth = useCallback ( ( ) => {
109
103
if ( containerRef . current ) {
110
104
return `${ containerRef . current . offsetWidth - 2 } px` ;
111
105
}
112
106
return 'auto' ;
113
- } , [ containerRef . current ?. offsetWidth ] ) ;
107
+ } , [ ] ) ;
114
108
115
109
const dropdrownPosition = useCallback ( ( ) => {
116
110
if ( containerRef . current ) {
117
111
return containerRef . current . offsetHeight + 1 ;
118
112
}
119
113
return 33 ;
120
- } , [ containerRef . current ?. offsetHeight ] ) ;
121
-
122
- const DropdownWrapper : FC < { children : any ; refEl : any } > = ( {
123
- children,
124
- refEl,
125
- // eslint-disable-next-line arrow-body-style
126
- } ) => {
127
- return appendToBody ? (
128
- < StickyPortal refEl = { refEl } handleClose = { handleClickOutside } >
129
- { children }
130
- </ StickyPortal >
131
- ) : (
132
- children
133
- ) ;
134
- } ;
114
+ } , [ ] ) ;
135
115
136
116
return (
137
117
< Label
@@ -161,7 +141,11 @@ const EditableSelect: FC<EditableSelectProps> = ({
161
141
variant = { disabled ? 'disabled' : ( variant as ChipsVariants ) }
162
142
>
163
143
{ isOpen && (
164
- < DropdownWrapper refEl = { containerRef ?. current || undefined } >
144
+ < DropdownWrapper
145
+ containerRef = { containerRef }
146
+ appendToBody = { appendToBody }
147
+ onClickOutside = { handleClickOutside }
148
+ >
165
149
< EditableSelectDropdown
166
150
type = { type }
167
151
value = { value }
0 commit comments