Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Reuse the tabbable utility to retrieve the tabbables elements in WritingFlow #2696

Merged
merged 1 commit into from
Sep 16, 2017
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
18 changes: 9 additions & 9 deletions editor/writing-flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { Component } from 'element';
import { keycodes } from '@wordpress/utils';
import { keycodes, focus } from '@wordpress/utils';

/**
* Internal dependencies
Expand Down Expand Up @@ -31,14 +31,14 @@ class WritingFlow extends Component {
}

getVisibleTabbables() {
const tabbablesSelector = [
'*[contenteditable="true"]',
'*[tabindex]:not([tabindex="-1"])',
'textarea',
'input',
].join( ', ' );
const isVisible = ( elem ) => elem.offsetWidth > 0 || elem.offsetHeight > 0 || elem.getClientRects().length > 0;
return [ ...this.container.querySelectorAll( tabbablesSelector ) ].filter( isVisible );
return focus.tabbable
.find( this.container )
.filter( ( node ) => (
node.nodeName === 'INPUT' ||
node.nodeName === 'TEXTAREA' ||
node.contentEditable === 'true' ||
node.classList.contains( 'editor-visual-editor__block' )
) );
}

moveFocusInContainer( target, direction = 'UP' ) {
Expand Down