From c17b668fefd095ec3b757175b3f88d5458b9027b Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Wed, 11 Apr 2018 21:03:47 +0200 Subject: [PATCH] Make Popover initial focus work with screen readers. (#5732) --- components/popover/index.js | 17 ++--------------- components/popover/test/index.js | 6 ------ 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/components/popover/index.js b/components/popover/index.js index db069021ab8b45..62f7c6712a6217 100644 --- a/components/popover/index.js +++ b/components/popover/index.js @@ -2,7 +2,7 @@ * External dependencies */ import classnames from 'classnames'; -import { defer, isEqual, noop } from 'lodash'; +import { isEqual, noop } from 'lodash'; /** * WordPress dependencies @@ -20,19 +20,6 @@ import IconButton from '../icon-button'; import ScrollLock from '../scroll-lock'; import { Slot, Fill } from '../slot-fill'; -/** - * Value representing whether a key is currently pressed. Bound to the document - * for use in determining whether the Popover component has mounted in response - * to a keyboard event. Popover's focusOnMount behavior is specific to keyboard - * interaction. Must be bound at the top-level and its unsetting deferred since - * the component will have already mounted by the time keyup occurs. - * - * @type {boolean} - */ -let isKeyDown = false; -document.addEventListener( 'keydown', () => isKeyDown = true ); -document.addEventListener( 'keyup', defer.bind( null, () => isKeyDown = false ) ); - const FocusManaged = withFocusReturn( ( { children } ) => children ); const { ESCAPE } = keycodes; @@ -108,7 +95,7 @@ class Popover extends Component { focus() { const { focusOnMount = true } = this.props; - if ( ! focusOnMount || ! isKeyDown ) { + if ( ! focusOnMount ) { return; } diff --git a/components/popover/test/index.js b/components/popover/test/index.js index f6bb7dbe7eccc7..7fb17499a924e4 100644 --- a/components/popover/test/index.js +++ b/components/popover/test/index.js @@ -83,12 +83,6 @@ describe( 'Popover', () => { expect( document.activeElement ).toBe( content ); } ); - it( 'should not focus when opening in response to pointer event', () => { - wrapper = mount( ); - - expect( document.activeElement ).toBe( document.body ); - } ); - it( 'should allow focus-on-open behavior to be disabled', () => { const activeElement = document.activeElement;