File tree Expand file tree Collapse file tree 6 files changed +36
-4
lines changed Expand file tree Collapse file tree 6 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15
15
- Fix hanging tests when using ` anchor ` prop ([ #3357 ] ( https://github.com/tailwindlabs/headlessui/pull/3357 ) )
16
16
- Fix ` transition ` and ` focus ` prop combination for ` PopoverPanel ` component ([ #3361 ] ( https://github.com/tailwindlabs/headlessui/pull/3361 ) )
17
17
- Fix outside click in nested portalled ` Popover ` components ([ #3362 ] ( https://github.com/tailwindlabs/headlessui/pull/3362 ) )
18
+ - Fix restoring focus to correct element when closing ` Dialog ` component ([ #3365 ] ( https://github.com/tailwindlabs/headlessui/pull/3365 ) )
18
19
19
20
## [ 2.1.1] - 2024-06-26
20
21
Original file line number Diff line number Diff line change 1
1
import { onDocumentReady } from './document-ready'
2
+ import { focusableSelector } from './focus-management'
2
3
3
4
export let history : HTMLElement [ ] = [ ]
4
5
onDocumentReady ( ( ) => {
@@ -7,7 +8,21 @@ onDocumentReady(() => {
7
8
if ( e . target === document . body ) return
8
9
if ( history [ 0 ] === e . target ) return
9
10
10
- history . unshift ( e . target )
11
+ let focusableElement = e . target as HTMLElement
12
+
13
+ // Figure out the closest focusable element, this is needed in a situation
14
+ // where you click on a non-focusable element inside a focusable element.
15
+ //
16
+ // E.g.:
17
+ //
18
+ // ```html
19
+ // <button>
20
+ // <span>Click me</span>
21
+ // </button>
22
+ // ```
23
+ focusableElement = focusableElement . closest ( focusableSelector ) as HTMLElement
24
+
25
+ history . unshift ( focusableElement ?? e . target )
11
26
12
27
// Filter out DOM Nodes that don't exist anymore
13
28
history = history . filter ( ( x ) => x != null && x . isConnected )
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { getOwnerDocument } from './owner'
5
5
6
6
// Credit:
7
7
// - https://stackoverflow.com/a/30753870
8
- let focusableSelector = [
8
+ export let focusableSelector = [
9
9
'[contentEditable=true]' ,
10
10
'[tabindex]' ,
11
11
'a[href]' ,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15
15
### Fixed
16
16
17
17
- Cancel outside click behavior on touch devices when scrolling ([ #3266 ] ( https://github.com/tailwindlabs/headlessui/pull/3266 ) )
18
+ - Fix restoring focus to correct element when closing ` Dialog ` component ([ #3365 ] ( https://github.com/tailwindlabs/headlessui/pull/3365 ) )
18
19
19
20
## [ 1.7.22] - 2024-05-08
20
21
Original file line number Diff line number Diff line change 1
1
import { onDocumentReady } from './document-ready'
2
+ import { focusableSelector } from './focus-management'
2
3
3
4
export let history : HTMLElement [ ] = [ ]
4
5
onDocumentReady ( ( ) => {
@@ -7,7 +8,21 @@ onDocumentReady(() => {
7
8
if ( e . target === document . body ) return
8
9
if ( history [ 0 ] === e . target ) return
9
10
10
- history . unshift ( e . target )
11
+ let focusableElement = e . target as HTMLElement
12
+
13
+ // Figure out the closest focusable element, this is needed in a situation
14
+ // where you click on a non-focusable element inside a focusable element.
15
+ //
16
+ // E.g.:
17
+ //
18
+ // ```html
19
+ // <button>
20
+ // <span>Click me</span>
21
+ // </button>
22
+ // ```
23
+ focusableElement = focusableElement . closest ( focusableSelector ) as HTMLElement
24
+
25
+ history . unshift ( focusableElement ?? e . target )
11
26
12
27
// Filter out DOM Nodes that don't exist anymore
13
28
history = history . filter ( ( x ) => x != null && x . isConnected )
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { getOwnerDocument } from './owner'
4
4
5
5
// Credit:
6
6
// - https://stackoverflow.com/a/30753870
7
- let focusableSelector = [
7
+ export let focusableSelector = [
8
8
'[contentEditable=true]' ,
9
9
'[tabindex]' ,
10
10
'a[href]' ,
You can’t perform that action at this time.
0 commit comments