-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Writing Flow: Avoid horizontal writing flow navigation in native inpu…
…ts (#9978)
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { isNavigationCandidate } from '../'; | ||
|
||
describe( 'isNavigationCandidate', () => { | ||
let elements; | ||
beforeAll( () => { | ||
elements = {}; | ||
elements.input = document.createElement( 'input' ); | ||
elements.contentEditable = document.createElement( 'p' ); | ||
elements.contentEditable.contentEditable = true; | ||
} ); | ||
|
||
it( 'should return true if vertically navigating input without modifier', () => { | ||
[ UP, DOWN ].forEach( ( keyCode ) => { | ||
const result = isNavigationCandidate( elements.input, keyCode, false ); | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
} ); | ||
|
||
it( 'should return false if vertically navigating input with modifier', () => { | ||
[ UP, DOWN ].forEach( ( keyCode ) => { | ||
const result = isNavigationCandidate( elements.input, keyCode, true ); | ||
|
||
expect( result ).toBe( false ); | ||
} ); | ||
} ); | ||
|
||
it( 'should return false if horizontally navigating input', () => { | ||
[ LEFT, RIGHT ].forEach( ( keyCode ) => { | ||
const result = isNavigationCandidate( elements.input, keyCode, false ); | ||
|
||
expect( result ).toBe( false ); | ||
} ); | ||
} ); | ||
|
||
it( 'should return true if horizontally navigating non-input', () => { | ||
[ LEFT, RIGHT ].forEach( ( keyCode ) => { | ||
const result = isNavigationCandidate( elements.contentEditable, keyCode, false ); | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters