From 3bd47853a1adce924978356ce98dcc10539bf021 Mon Sep 17 00:00:00 2001 From: Tomi Virkki Date: Wed, 19 Jun 2024 09:12:33 +0300 Subject: [PATCH] refactor: remove duplicate logic from grid isFocusable (#7491) --- .../grid/src/vaadin-grid-active-item-mixin.js | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/grid/src/vaadin-grid-active-item-mixin.js b/packages/grid/src/vaadin-grid-active-item-mixin.js index c31858f36cc..425d431dc79 100644 --- a/packages/grid/src/vaadin-grid-active-item-mixin.js +++ b/packages/grid/src/vaadin-grid-active-item-mixin.js @@ -4,27 +4,19 @@ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { isElementFocusable } from '@vaadin/a11y-base/src/focus-utils.js'; + /** * @param {!Element} target * @return {boolean} * @protected */ export const isFocusable = (target) => { - if (!target.parentNode) { - return false; - } - const focusables = Array.from( - target.parentNode.querySelectorAll( - '[tabindex], button, input, select, textarea, object, iframe, a[href], area[href]', - ), - ).filter((element) => { - const part = element.getAttribute('part'); - return !(part && part.includes('body-cell')); - }); - - const isFocusableElement = focusables.includes(target); return ( - !target.disabled && isFocusableElement && target.offsetParent && getComputedStyle(target).visibility !== 'hidden' + target.offsetParent && + !target.part.contains('body-cell') && + isElementFocusable(target) && + getComputedStyle(target).visibility !== 'hidden' ); };