@@ -6,10 +6,15 @@ import { useEffect, useMemo, useState } from 'react'
6
6
import { ReactComponent as ICFilter } from '@Icons/ic-filter.svg'
7
7
import { ReactComponent as ICFilterApplied } from '@Icons/ic-filter-applied.svg'
8
8
import { ComponentSizeType } from '@Shared/constants'
9
+ import { useRegisterShortcut , UseRegisterShortcutProvider } from '@Common/Hooks'
10
+ import { IS_PLATFORM_MAC_OS } from '@Common/Constants'
11
+ import { SupportedKeyboardKeysType } from '@Common/Hooks/UseRegisterShortcut/types'
9
12
import SelectPicker from './SelectPicker.component'
10
13
import { FilterSelectPickerProps , SelectPickerOptionType , SelectPickerProps } from './type'
11
14
import { Button } from '../Button'
12
15
16
+ const APPLY_FILTER_SHORTCUT_KEYS : SupportedKeyboardKeysType [ ] = [ IS_PLATFORM_MAC_OS ? 'Meta' : 'Control' , 'Enter' ]
17
+
13
18
const FilterSelectPicker = ( {
14
19
appliedFilterOptions,
15
20
handleApplyFilter,
@@ -23,6 +28,8 @@ const FilterSelectPicker = ({
23
28
structuredClone ( appliedFilterOptions ?? [ ] ) ,
24
29
)
25
30
31
+ const { registerShortcut, unregisterShortcut } = useRegisterShortcut ( )
32
+
26
33
const appliedFiltersCount = appliedFilterOptions ?. length ?? 0
27
34
28
35
useEffect ( ( ) => {
@@ -52,24 +59,39 @@ const FilterSelectPicker = ({
52
59
setSelectedOptions ( structuredClone ( appliedFilterOptions ?? [ ] ) )
53
60
}
54
61
55
- const renderApplyButton = ( ) => {
56
- const handleApplyClick = ( ) => {
57
- handleApplyFilter ( selectedOptions )
58
- closeMenu ( )
62
+ const handleApplyClick = ( ) => {
63
+ handleApplyFilter ( selectedOptions )
64
+ closeMenu ( )
65
+ }
66
+
67
+ const renderApplyButton = ( ) => (
68
+ < div className = "p-8 dc__border-top-n1" >
69
+ < Button
70
+ text = "Apply"
71
+ dataTestId = "filter-select-picker-apply"
72
+ onClick = { handleApplyClick }
73
+ size = { ComponentSizeType . small }
74
+ fullWidth
75
+ showTooltip
76
+ tooltipProps = { {
77
+ shortcutKeyCombo : {
78
+ text : 'Apply filter' ,
79
+ combo : APPLY_FILTER_SHORTCUT_KEYS ,
80
+ } ,
81
+ } }
82
+ />
83
+ </ div >
84
+ )
85
+
86
+ useEffect ( ( ) => {
87
+ if ( isMenuOpen ) {
88
+ registerShortcut ( { keys : APPLY_FILTER_SHORTCUT_KEYS , callback : handleApplyClick } )
59
89
}
60
90
61
- return (
62
- < div className = "p-8 dc__border-top-n1" >
63
- < Button
64
- text = "Apply"
65
- dataTestId = "filter-select-picker-apply"
66
- onClick = { handleApplyClick }
67
- size = { ComponentSizeType . small }
68
- fullWidth
69
- />
70
- </ div >
71
- )
72
- }
91
+ return ( ) => {
92
+ unregisterShortcut ( APPLY_FILTER_SHORTCUT_KEYS )
93
+ }
94
+ } , [ handleApplyClick , isMenuOpen ] )
73
95
74
96
return (
75
97
< div className = "dc__mxw-250" >
@@ -96,4 +118,10 @@ const FilterSelectPicker = ({
96
118
)
97
119
}
98
120
99
- export default FilterSelectPicker
121
+ const FilterSelectPickerWrapper = ( props : FilterSelectPickerProps ) => (
122
+ < UseRegisterShortcutProvider ignoreTags = { [ ] } >
123
+ < FilterSelectPicker { ...props } />
124
+ </ UseRegisterShortcutProvider >
125
+ )
126
+
127
+ export default FilterSelectPickerWrapper
0 commit comments