Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/compose/src/hooks/use-constrained-tabbing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ import useRefEffect from '../use-ref-effect';
*/
function useConstrainedTabbing() {
return useRefEffect( ( /** @type {HTMLElement} */ node ) => {
/** @type {number|undefined} */
let timeoutId;

function onKeyDown( /** @type {KeyboardEvent} */ event ) {
const { keyCode, shiftKey, target } = event;

Expand Down Expand Up @@ -62,15 +59,16 @@ function useConstrainedTabbing() {

trap.tabIndex = -1;
node[ domAction ]( trap );

// Remove itself when the trap loses focus.
trap.addEventListener( 'blur', () => node.removeChild( trap ) );

trap.focus();
// Remove after the browser moves focus to the next element.
timeoutId = setTimeout( () => node.removeChild( trap ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this timeout is not used any longer, the variable declaration at line 36 and the clearTimeout at line 75 should be removed as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed by 11a1cfa

}

node.addEventListener( 'keydown', onKeyDown );
return () => {
node.removeEventListener( 'keydown', onKeyDown );
clearTimeout( timeoutId );
};
}, [] );
}
Expand Down