Skip to content

Commit dc4111c

Browse files
committed
fix: focus state when apply filter is auto clicked
1 parent 89b24bb commit dc4111c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Shared/Components/SelectPicker/FilterSelectPicker.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect, useMemo, useState } from 'react'
17+
import { useEffect, useMemo, useRef, useState } from 'react'
1818
import { ReactComponent as ICFilter } from '@Icons/ic-filter.svg'
1919
import { ReactComponent as ICFilterApplied } from '@Icons/ic-filter-applied.svg'
2020
import { ComponentSizeType } from '@Shared/constants'
@@ -33,6 +33,8 @@ const FilterSelectPicker = ({
3333
options,
3434
...props
3535
}: FilterSelectPickerProps) => {
36+
const selectRef = useRef<SelectPickerProps<string | number, true>['selectRef']['current']>()
37+
3638
const [isMenuOpen, setIsMenuOpen] = useState(false)
3739
const { triggerAutoClickTimestamp, setTriggerAutoClickTimestampToNow, resetTriggerAutoClickTimestamp } =
3840
useTriggerAutoClickTimestamp()
@@ -81,6 +83,12 @@ const FilterSelectPicker = ({
8183
// Added !e to ensure it works for both click and keyboard shortcut event
8284
if (!e || e.isTrusted) {
8385
closeMenu()
86+
} else {
87+
// If the event is not triggered by the user, focus on the select picker
88+
// As it loses focus when auto-click is triggered and menu is not closed
89+
setTimeout(() => {
90+
selectRef.current.focus()
91+
}, 100)
8492
}
8593
}
8694

@@ -116,8 +124,9 @@ const FilterSelectPicker = ({
116124

117125
return (
118126
<div className="dc__mxw-250">
119-
<SelectPicker
127+
<SelectPicker<string | number, true>
120128
{...props}
129+
selectRef={selectRef}
121130
options={options}
122131
value={selectedOptions}
123132
isMulti

0 commit comments

Comments
 (0)