Skip to content

Commit

Permalink
Suppress block inserter focus loop (#33049)
Browse files Browse the repository at this point in the history
* Suppress block inserter focus loop

This introduces a setTimeout to suppress the focus loop issue that was uncovered by the block inserter search focus issue.

* Make focus loop bug workaround iOS-specific

* Update focus loop workaround for VoiceOver
  • Loading branch information
guarani authored Jul 5, 2021
1 parent f94af5c commit 71ae88a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/block-editor/src/components/inserter/menu.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* External dependencies
*/
import { LayoutAnimation, TouchableHighlight } from 'react-native';
import {
AccessibilityInfo,
LayoutAnimation,
TouchableHighlight,
Platform,
} from 'react-native';

/**
* WordPress dependencies
Expand Down Expand Up @@ -140,7 +145,19 @@ function InserterMenu( {

const onSelectItem = useCallback(
( item ) => {
onInsert( item );
// Avoid a focus loop, see https://github.com/WordPress/gutenberg/issues/30562
if ( Platform.OS === 'ios' ) {
AccessibilityInfo.isScreenReaderEnabled().then( ( enabled ) => {
// In testing, the bug focus loop needed a longer timeout when VoiceOver was enabled
const timeout = enabled ? 200 : 100;
// eslint-disable-next-line @wordpress/react-no-unsafe-timeout
setTimeout( () => {
onInsert( item );
}, timeout );
} );
} else {
onInsert( item );
}
onSelect( item );
},
[ onInsert, onSelect ]
Expand Down

0 comments on commit 71ae88a

Please sign in to comment.