Skip to content

Commit

Permalink
Simply focusable element type
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Feb 1, 2023
1 parent 34a29ff commit 52cbdd9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions packages/components/src/tree-grid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import RovingTabIndexContainer from './roving-tab-index';
import type { TreeGridProps } from './types';
import type { WordPressComponentProps } from '../ui/context';

type FocusableElement = Element & {
focus: ( options?: { preventScroll?: boolean } ) => void;
};

/**
* Return focusables in a row element, excluding those from other branches
* nested within the row.
Expand All @@ -27,7 +23,7 @@ type FocusableElement = Element & {
function getRowFocusables( rowElement: Element ) {
const focusablesInRow = focus.focusable.find( rowElement, {
sequential: true,
} ) as FocusableElement[];
} );

return focusablesInRow.filter( ( focusable ) => {
return focusable.closest( '[role="row"]' ) === rowElement;
Expand Down Expand Up @@ -89,7 +85,7 @@ function UnforwardedTreeGrid(

const focusablesInRow = getRowFocusables( activeRow );
const currentColumnIndex = focusablesInRow.indexOf(
activeElement as FocusableElement
activeElement as HTMLElement
);
const canExpandCollapse = 0 === currentColumnIndex;
const cannotFocusNextColumn =
Expand Down
2 changes: 1 addition & 1 deletion packages/dom/src/focusable.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function isValidFocusableArea( element ) {
* not sequentially focusable.
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
*
* @return {Element[]} Focusable elements.
* @return {HTMLElement[]} Focusable elements.
*/
export function find( context, { sequential = false } = {} ) {
/* eslint-disable jsdoc/no-undefined-types */
Expand Down

0 comments on commit 52cbdd9

Please sign in to comment.