File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
packages/web-components/src/components/tag Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,25 @@ class CDSDismissibleTag extends HostListenerMixin(FocusMixin(CDSTag)) {
35
35
@query ( 'button' )
36
36
protected _buttonNode ! : HTMLButtonElement ;
37
37
38
+ /**
39
+ * Finds the next focusable dismissible tag sibling
40
+ * @returns {HTMLElement|null } The next focusable dismissible tag or null
41
+ */
42
+ protected _findNextFocusableTag ( ) {
43
+ let nextElement = this . nextElementSibling ;
44
+ while ( nextElement ) {
45
+ if (
46
+ nextElement . tagName . toLowerCase ( ) === `${ prefix } -dismissible-tag` &&
47
+ ! nextElement . hasAttribute ( 'disabled' ) &&
48
+ ( nextElement as HTMLElement ) . getAttribute ( 'open' ) !== 'false'
49
+ ) {
50
+ return nextElement ;
51
+ }
52
+ nextElement = nextElement . nextElementSibling ;
53
+ }
54
+ return null ;
55
+ }
56
+
38
57
/**
39
58
* Handles `slotchange` event.
40
59
*/
@@ -73,6 +92,7 @@ class CDSDismissibleTag extends HostListenerMixin(FocusMixin(CDSTag)) {
73
92
if ( this . disabled ) {
74
93
event . stopPropagation ( ) ;
75
94
} else if ( this . open ) {
95
+ const nextFocusableTag = this . _findNextFocusableTag ( ) ;
76
96
const init = {
77
97
bubbles : true ,
78
98
cancelable : true ,
@@ -90,6 +110,13 @@ class CDSDismissibleTag extends HostListenerMixin(FocusMixin(CDSTag)) {
90
110
)
91
111
) {
92
112
this . open = false ;
113
+ if ( nextFocusableTag ) {
114
+ const nextCloseIcon = ( nextFocusableTag as CDSDismissibleTag )
115
+ . _buttonNode ;
116
+ if ( nextCloseIcon ) {
117
+ nextCloseIcon . focus ( ) ;
118
+ }
119
+ }
93
120
this . dispatchEvent (
94
121
new CustomEvent (
95
122
( this . constructor as typeof CDSDismissibleTag ) . eventClose ,
You can’t perform that action at this time.
0 commit comments