File tree Expand file tree Collapse file tree 3 files changed +33
-4
lines changed
packages/block-editor/src/components/writing-flow
test/e2e/specs/editor/various Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ describe( 'isNavigationCandidate', () => {
1919 elements . inputCheckbox = document . createElement ( 'input' ) ;
2020 elements . inputCheckbox . setAttribute ( 'type' , 'checkbox' ) ;
2121
22+ elements . inputNumber = document . createElement ( 'input' ) ;
23+ elements . inputNumber . setAttribute ( 'type' , 'number' ) ;
24+
2225 elements . contentEditable = document . createElement ( 'p' ) ;
2326 elements . contentEditable . contentEditable = true ;
2427 } ) ;
@@ -47,6 +50,18 @@ describe( 'isNavigationCandidate', () => {
4750 } ) ;
4851 } ) ;
4952
53+ it ( 'should return false if vertically navigating inputs with vertial support like number' , ( ) => {
54+ [ UP , DOWN ] . forEach ( ( keyCode ) => {
55+ const result = isNavigationCandidate (
56+ elements . inputNumber ,
57+ keyCode ,
58+ false
59+ ) ;
60+
61+ expect ( result ) . toBe ( false ) ;
62+ } ) ;
63+ } ) ;
64+
5065 it ( 'should return false if horizontally navigating input' , ( ) => {
5166 [ LEFT , RIGHT ] . forEach ( ( keyCode ) => {
5267 const result = isNavigationCandidate (
Original file line number Diff line number Diff line change @@ -32,27 +32,40 @@ import { store as blockEditorStore } from '../../store';
3232 */
3333export function isNavigationCandidate ( element , keyCode , hasModifier ) {
3434 const isVertical = keyCode === UP || keyCode === DOWN ;
35+ const { tagName } = element ;
36+ const elementType = element . getAttribute ( 'type' ) ;
3537
36- // Currently, all elements support unmodified vertical navigation .
38+ // Native inputs should not navigate vertically, unless they are simple types that don't need up/down arrow keys .
3739 if ( isVertical && ! hasModifier ) {
40+ if ( tagName === 'INPUT' ) {
41+ const verticalInputTypes = [
42+ 'date' ,
43+ 'datetime-local' ,
44+ 'month' ,
45+ 'number' ,
46+ 'range' ,
47+ 'time' ,
48+ 'week' ,
49+ ] ;
50+ return ! verticalInputTypes . includes ( elementType ) ;
51+ }
3852 return true ;
3953 }
4054
41- const { tagName } = element ;
42-
4355 // Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.
4456 if ( tagName === 'INPUT' ) {
4557 const simpleInputTypes = [
4658 'button' ,
4759 'checkbox' ,
60+ 'number' ,
4861 'color' ,
4962 'file' ,
5063 'image' ,
5164 'radio' ,
5265 'reset' ,
5366 'submit' ,
5467 ] ;
55- return simpleInputTypes . includes ( element . getAttribute ( 'type' ) ) ;
68+ return simpleInputTypes . includes ( elementType ) ;
5669 }
5770
5871 // Native textareas should not navigate horizontally.
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ test.describe( 'Toolbar roving tabindex', () => {
9696 pageUtils,
9797 } ) => {
9898 await editor . insertBlock ( { name : 'core/table' } ) ;
99+ await page . keyboard . press ( 'ArrowLeft' ) ;
99100 await ToolbarRovingTabindexUtils . testBlockToolbarKeyboardNavigation (
100101 'Block: Table' ,
101102 'Table'
You can’t perform that action at this time.
0 commit comments