File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## [ UNRELEASED]
99
10+ ### Fixed
11+
12+ - ` Select ` inside a ` Dialog ` losing focus after clicking an option
13+
1014### Changed
1115
1216- ` InputFiltersChipEditor ` can use CheckboxGroup or RadioGroup.
Original file line number Diff line number Diff line change @@ -74,10 +74,20 @@ export function useFocusTrap(
7474 clickOutsideDeactivates : true ,
7575 escapeDeactivates : false ,
7676 fallbackFocus : element ,
77+ initialFocus :
78+ autoFocusElement || surfaceElement
79+ ? ( ) => {
80+ // Check first if focus is already within the element
81+ // otherwise if focus trap is disabled then re-enabled
82+ // (e.g. when a Select closes inside a Dialog)
83+ // focus will move unnecessarily back to the surface / autoFocus element
84+ if ( element . contains ( document . activeElement ) ) {
85+ return document . activeElement as HTMLElement
86+ }
87+ return autoFocusElement || surfaceElement
88+ }
89+ : undefined ,
7790 onDeactivate : ( ) => setOff ( ) ,
78- ...( autoFocusElement || surfaceElement
79- ? { initialFocus : autoFocusElement || surfaceElement }
80- : { } ) ,
8191 } )
8292 }
8393 disableFocusTrap && disableFocusTrap ( )
You can’t perform that action at this time.
0 commit comments