Skip to content

Commit e93f48e

Browse files
authored
fix(multiple): avoid instanceof checks in aria directives (#33587)
We were using `instanceof HTMLElement` in a few Aria directives. This excludes SVG elements and can be problematic for SSR. Fixes #33586.
1 parent 464891b commit e93f48e

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/aria/private/listbox/listbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ export class ListboxPattern<V> {
292292
}
293293

294294
protected _getItem(e: PointerEvent) {
295-
if (!(e.target instanceof HTMLElement)) {
295+
if (!e.target) {
296296
return;
297297
}
298298

299-
const element = e.target.closest('[role="option"]');
299+
const element = (e.target as Element).closest('[role="option"]');
300300
return this.inputs.items().find(i => i.element() === element);
301301
}
302302
}

src/aria/private/tabs/tabs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,11 @@ export class TabListPattern {
296296

297297
/** Returns the tab item associated with the given pointer event. */
298298
private _getItem(e: PointerEvent) {
299-
if (!(e.target instanceof HTMLElement)) {
299+
if (!e.target) {
300300
return;
301301
}
302302

303-
const element = e.target.closest('[role="tab"]');
303+
const element = (e.target as Element).closest('[role="tab"]');
304304
return this.inputs.items().find(i => i.element() === element);
305305
}
306306
}

src/aria/private/tree/tree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,10 @@ export class TreePattern<V> implements TreeInputs<V> {
479479

480480
/** Retrieves the TreeItemPattern associated with a DOM event, if any. */
481481
protected _getItem(event: Event): TreeItemPattern<V> | undefined {
482-
if (!(event.target instanceof HTMLElement)) {
482+
if (!event.target) {
483483
return;
484484
}
485-
const element = event.target.closest('[role="treeitem"]');
485+
const element = (event.target as Element).closest('[role="treeitem"]');
486486
return this.inputs.items().find(i => i.element() === element);
487487
}
488488
}

0 commit comments

Comments
 (0)