@@ -7,8 +7,12 @@ import {
7
7
Button ,
8
8
Alert ,
9
9
TextInput ,
10
+ Select ,
11
+ MenuToggleElement ,
12
+ MenuToggle ,
13
+ SelectList ,
14
+ SelectOption ,
10
15
} from '@patternfly/react-core' ;
11
- import { Select , SelectOption } from '@patternfly/react-core/deprecated' ;
12
16
import { HelpIcon , MinusCircleIcon } from '@patternfly/react-icons' ;
13
17
import styles from '@patternfly/react-styles/css/components/Table/table' ;
14
18
import {
@@ -163,6 +167,8 @@ export const mountpointPrefixes = [
163
167
'/var' ,
164
168
] ;
165
169
170
+ const units = [ 'GiB' , 'MiB' , 'KiB' ] ;
171
+
166
172
type MountpointPrefixPropTypes = {
167
173
partition : Partition ;
168
174
} ;
@@ -173,10 +179,6 @@ const MountpointPrefix = ({ partition }: MountpointPrefixPropTypes) => {
173
179
const prefix = getPrefix ( partition . mountpoint ) ;
174
180
const suffix = getSuffix ( partition . mountpoint ) ;
175
181
176
- const onToggle = ( isOpen : boolean ) => {
177
- setIsOpen ( isOpen ) ;
178
- } ;
179
-
180
182
const onSelect = ( event : React . MouseEvent , selection : string ) => {
181
183
setIsOpen ( false ) ;
182
184
const mountpoint = selection + ( suffix . length > 0 ? '/' + suffix : '' ) ;
@@ -185,18 +187,42 @@ const MountpointPrefix = ({ partition }: MountpointPrefixPropTypes) => {
185
187
) ;
186
188
} ;
187
189
190
+ const onToggleClick = ( ) => {
191
+ setIsOpen ( ! isOpen ) ;
192
+ } ;
193
+
194
+ const toggle = ( toggleRef : React . Ref < MenuToggleElement > ) => (
195
+ < MenuToggle
196
+ ref = { toggleRef }
197
+ onClick = { onToggleClick }
198
+ isExpanded = { isOpen }
199
+ isDisabled = { prefix === '/' }
200
+ data-testid = "prefix-select"
201
+ isFullWidth
202
+ >
203
+ { prefix }
204
+ </ MenuToggle >
205
+ ) ;
206
+
188
207
return (
189
208
< Select
190
209
ouiaId = "mount-point"
191
210
isOpen = { isOpen }
192
- onToggle = { ( _event , isOpen ) => onToggle ( isOpen ) }
211
+ selected = { prefix }
193
212
onSelect = { onSelect }
194
- selections = { prefix }
195
- isDisabled = { prefix === '/' }
213
+ onOpenChange = { ( isOpen ) => setIsOpen ( isOpen ) }
214
+ toggle = { toggle }
215
+ shouldFocusToggleOnSelect
196
216
>
197
- { mountpointPrefixes . map ( ( prefix , index ) => {
198
- return < SelectOption key = { index } value = { prefix } /> ;
199
- } ) }
217
+ < SelectList >
218
+ { mountpointPrefixes . map ( ( prefix , index ) => {
219
+ return (
220
+ < SelectOption key = { index } value = { prefix } >
221
+ { prefix }
222
+ </ SelectOption >
223
+ ) ;
224
+ } ) }
225
+ </ SelectList >
200
226
</ Select >
201
227
) ;
202
228
} ;
@@ -291,10 +317,6 @@ const SizeUnit = ({ partition }: SizeUnitPropTypes) => {
291
317
const dispatch = useAppDispatch ( ) ;
292
318
const [ isOpen , setIsOpen ] = useState ( false ) ;
293
319
294
- const onToggle = ( isOpen : boolean ) => {
295
- setIsOpen ( isOpen ) ;
296
- } ;
297
-
298
320
const initialValue = useRef ( partition ) . current ;
299
321
300
322
const onSelect = ( event : React . MouseEvent , selection : Units ) => {
@@ -310,18 +332,43 @@ const SizeUnit = ({ partition }: SizeUnitPropTypes) => {
310
332
setIsOpen ( false ) ;
311
333
} ;
312
334
335
+ const onToggleClick = ( ) => {
336
+ setIsOpen ( ! isOpen ) ;
337
+ } ;
338
+
339
+ const toggle = ( toggleRef : React . Ref < MenuToggleElement > ) => (
340
+ < MenuToggle
341
+ ref = { toggleRef }
342
+ onClick = { onToggleClick }
343
+ isExpanded = { isOpen }
344
+ data-testid = "unit-select"
345
+ >
346
+ { partition . unit }
347
+ </ MenuToggle >
348
+ ) ;
349
+
313
350
return (
314
351
< Select
315
352
ouiaId = "unit"
316
353
isOpen = { isOpen }
317
- onToggle = { ( _event , isOpen ) => onToggle ( isOpen ) }
354
+ selected = { partition . unit }
318
355
onSelect = { onSelect }
319
- selections = { partition . unit }
356
+ onOpenChange = { ( isOpen ) => setIsOpen ( isOpen ) }
357
+ toggle = { toggle }
358
+ shouldFocusToggleOnSelect
320
359
>
321
- < SelectOption value = { 'KiB' } />
322
- < SelectOption value = { 'MiB' } />
323
- < SelectOption value = { 'GiB' } />
324
- < > { initialValue . unit === 'B' && < SelectOption value = { 'B' } /> } </ >
360
+ < SelectList >
361
+ { units . map ( ( unit , index ) => (
362
+ < SelectOption key = { index } value = { unit } >
363
+ { unit }
364
+ </ SelectOption >
365
+ ) ) }
366
+ < >
367
+ { initialValue . unit === 'B' && (
368
+ < SelectOption value = { 'B' } > B</ SelectOption >
369
+ ) }
370
+ </ >
371
+ </ SelectList >
325
372
</ Select >
326
373
) ;
327
374
} ;
0 commit comments