File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @clack/ui ' : minor
3+ ---
4+
5+ Reflect the inert attribute on HTML elements and prevent programmatic focus inside inert subtrees.
Original file line number Diff line number Diff line change @@ -892,10 +892,28 @@ export class HTMLElement extends Element {
892892 #onfocus: EventListener | undefined = undefined ;
893893 #onblur: EventListener | undefined = undefined ;
894894
895+ get inert ( ) : boolean {
896+ return this . hasAttributeNS ( null , 'inert' ) ;
897+ }
898+
899+ set inert ( value : boolean ) {
900+ if ( value ) {
901+ this . setAttributeNS ( null , 'inert' , '' ) ;
902+ } else {
903+ this . removeAttributeNS ( null , 'inert' ) ;
904+ }
905+ }
906+
895907 focus ( ) : void {
896908 if ( ! this . isConnected ) {
897909 return ;
898910 }
911+ // inert nodes don't get focus
912+ for ( const node of lineage ( this ) ) {
913+ if ( node instanceof HTMLElement && node . inert ) {
914+ return ;
915+ }
916+ }
899917 this . ownerDocument . _setActiveElement ( this ) ;
900918 }
901919
@@ -1020,3 +1038,9 @@ function dispatchEvent(
10201038 }
10211039 }
10221040}
1041+
1042+ function * lineage ( node : Node ) : Iterable < Node > {
1043+ for ( let current : Node | null = node ; current ; current = current . parentNode ) {
1044+ yield current ;
1045+ }
1046+ }
Original file line number Diff line number Diff line change @@ -97,6 +97,8 @@ const config: WPTConfig = {
9797 'html/editing/focus/focus-management/focusing-disconnected-noop.html' : true ,
9898 'html/editing/focus/focus-management/focusing-focused-noop.html' : true ,
9999 'html/interaction/focus/focus-management/focus-events.html' : true ,
100+ 'inert/inert-node-is-unfocusable.html' : true ,
101+ 'inert/nested-inert-unfocusable.html' : true ,
100102 'dom/nodes/Document-getElementsByTagName.html' : [
101103 'Caching is allowed' ,
102104 "Shouldn't be able to set unsigned properties on a HTMLCollection (non-strict mode)" ,
You can’t perform that action at this time.
0 commit comments