Skip to content

Commit

Permalink
refactor: remove duplicate logic from grid isFocusable (#7491)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Jun 19, 2024
1 parent ef3d165 commit 3bd4785
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions packages/grid/src/vaadin-grid-active-item-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
};

Expand Down

0 comments on commit 3bd4785

Please sign in to comment.