2828 <tr v-for =" (row, i) in years" :key =" i" >
2929 <td
3030 v-for =" (cell, j) in row"
31- :ref =" handleRef (cell)"
31+ :ref =" handleRefName (cell, i, j )"
3232 :key =" j"
3333 aria-hidden =" false"
3434 class =" cell"
3535 role =" button"
3636 :tabindex =" handleTabIndex(cell)"
3737 :data-year =" cell"
3838 :class =" getCellClasses(cell)"
39- @blur.prevent =" onBlur(i, j)"
4039 @keydown.tab.prevent.stop
41- @keydown.up.prevent =" handleArrowUp(i, j)"
42- @keydown.down.prevent =" handleArrowDown(i, j)"
43- @keydown.left.prevent =" handleArrowLeft(i, j)"
44- @keydown.right.prevent =" handleArrowRight(i, j)"
40+ @keydown.up.prevent =" handleArrowUp(cell, i, j)"
41+ @keydown.down.prevent =" handleArrowDown(cell, i, j)"
42+ @keydown.left.prevent =" handleArrowLeft(cell, i, j)"
43+ @keydown.right.prevent =" handleArrowRight(cell, i, j)"
4544 >
4645 <div >{{ cell }}</div >
4746 </td >
5453<script >
5554import IconButton from ' ./icon-button' ;
5655import { chunk } from ' ../util/base' ;
57- import { setYear } from ' ../util/date' ;
56+ import { createDate , setYear } from ' ../util/date' ;
5857import { getLocale } from ' ../locale' ;
5958
6059export default {
@@ -84,6 +83,10 @@ export default {
8483 getYearPanel: {
8584 type: Function ,
8685 },
86+ isDisabled: {
87+ type: Function ,
88+ default : () => false ,
89+ },
8790 },
8891 computed: {
8992 years () {
@@ -103,6 +106,12 @@ export default {
103106 locale () {
104107 return this .getLocale ();
105108 },
109+ refsArray () {
110+ if (this .$refs ) {
111+ return Object .entries (this .$refs );
112+ }
113+ return [];
114+ },
106115 },
107116 methods: {
108117 isDisabledArrows (type ) {
@@ -128,66 +137,64 @@ export default {
128137 }
129138 return chunk (years, 2 );
130139 },
131- handleArrowUp (row , column ) {
140+ handleArrowUp (cell , row , column ) {
132141 if (row === 0 ) {
133142 return ;
134143 }
135- const year = this .years [ row - 1 ][ column] ;
136- const ref = this .$refs [` year-cell- ${ year } ` ]? .[0 ];
144+ const refName = this .handleRefName (cell, row - 1 , column) ;
145+ const ref = this .$refs [refName ]? .[0 ];
137146 if (ref) {
138147 ref .focus ();
139- ref .classList .add (' focus' );
140148 }
141149 },
142- handleArrowDown (row , column ) {
150+ handleArrowDown (cell , row , column ) {
143151 if (row === this .years .length - 1 ) {
144152 return ;
145153 }
146- const year = this .years [ row + 1 ][ column] ;
147- const ref = this .$refs [` year-cell- ${ year } ` ]? .[0 ];
154+ const refName = this .handleRefName (cell, row + 1 , column) ;
155+ const ref = this .$refs [refName ]? .[0 ];
148156 if (ref) {
149157 ref .focus ();
150- ref .classList .add (' focus' );
151158 }
152159 },
153- handleArrowLeft (row , column ) {
154- if (column % 2 === 0 ) {
155- if (row === 0 && column === 0 ) {
156- this .handleIconDoubleLeftClick ();
157- const ref = this .$refs [` year-cell-${ this .lastYear } ` ]? .[0 ];
158- if (ref) {
159- ref .focus ();
160+ handleArrowLeft (cell , row , column ) {
161+ const currentRefName = this .handleRefName (cell, row, column);
162+ const firstRef = this .refsArray [0 ];
163+ if (currentRefName !== firstRef[0 ]) {
164+ const refName = this .handleRefName (cell, row, column - 1 );
165+ const ref = this .$refs [refName]? .[0 ];
166+ if (ref) {
167+ ref .focus ();
168+ }
169+ } else {
170+ this .handleIconDoubleLeftClick ();
171+ const lastRef = this .refsArray [this .refsArray .length - 1 ];
172+ if (lastRef .length ) {
173+ const element = lastRef[1 ];
174+ if (element .length ) {
175+ element[0 ].focus ();
160176 }
161177 }
162- return ;
163- }
164- const year = this .years [row][column - 1 ];
165- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
166- if (ref) {
167- ref .focus ();
168- ref .classList .add (' focus' );
169178 }
170179 },
171- handleArrowRight (row , column ) {
172- if (column % 2 === 1 ) {
173- if (row === this .years .length - 1 ) {
174- const lastRow = this .years [row];
175- if (column === lastRow .length - 1 ) {
176- this .handleIconDoubleRightClick ();
177- const year = this .years [0 ][0 ];
178- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
179- if (ref) {
180- ref .focus ();
181- }
180+ handleArrowRight (cell , row , column ) {
181+ const currentRefName = this .handleRefName (cell, row, column);
182+ const lastRef = this .refsArray [this .refsArray .length - 1 ];
183+ if (currentRefName !== lastRef[0 ]) {
184+ const refName = this .handleRefName (cell, row, column + 1 );
185+ const ref = this .$refs [refName]? .[0 ];
186+ if (ref) {
187+ ref .focus ();
188+ }
189+ } else {
190+ this .handleIconDoubleRightClick ();
191+ const firstRef = this .refsArray [0 ];
192+ if (firstRef .length ) {
193+ const element = firstRef[1 ];
194+ if (element .length ) {
195+ element[0 ].focus ();
182196 }
183197 }
184- return ;
185- }
186- const year = this .years [row][column + 1 ];
187- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
188- if (ref) {
189- ref .focus ();
190- ref .classList .add (' focus' );
191198 }
192199 },
193200 handleIconDoubleLeftClick () {
@@ -215,28 +222,16 @@ export default {
215222 this .selectedYear = parseInt (year, 10 );
216223 }
217224 },
218- handleRef (cellDate ) {
219- return this .disabledCalendarChanger (cellDate, ' year' ) ? undefined : ` year-cell-${ cellDate} ` ;
220- },
221- handleTabIndex (cellDate ) {
222- return this .disabledCalendarChanger (cellDate, ' year' ) ? - 1 : 0 ;
223- },
224- moveToFirstCell () {
225- const year = this .years [0 ][0 ];
226- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
227- if (ref) {
228- setTimeout (() => {
229- ref .focus ();
230- ref .classList .add (' focus' );
231- }, 1 );
225+ handleRefName (cellDate , row , col ) {
226+ const date = createDate (cellDate, 0 );
227+ if (! this .isDisabled (date)) {
228+ return ` year-cell-${ row} -${ col} ` ;
232229 }
230+ return undefined ;
233231 },
234- onBlur (i , j ) {
235- const year = this .years [i][j];
236- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
237- if (ref) {
238- ref .classList .remove (' focus' );
239- }
232+ handleTabIndex (cellDate ) {
233+ const date = createDate (cellDate, 0 );
234+ return this .isDisabled (date) ? - 1 : 0 ;
240235 },
241236 },
242237};
0 commit comments