2626 <tr v-for =" (row, i) in years" :key =" i" >
2727 <td
2828 v-for =" (cell, j) in row"
29- :ref =" handleRef (cell)"
29+ :ref =" handleRefName (cell, i, j )"
3030 :key =" j"
3131 aria-hidden =" false"
3232 class =" cell"
3333 role =" button"
3434 :tabindex =" handleTabIndex(cell)"
3535 :data-year =" cell"
3636 :class =" getCellClasses(cell)"
37- @blur.prevent =" onBlur(i, j)"
3837 @keydown.tab.prevent.stop
39- @keydown.up.prevent =" handleArrowUp(i, j)"
40- @keydown.down.prevent =" handleArrowDown(i, j)"
41- @keydown.left.prevent =" handleArrowLeft(i, j)"
42- @keydown.right.prevent =" handleArrowRight(i, j)"
38+ @keydown.up.prevent =" handleArrowUp(cell, i, j)"
39+ @keydown.down.prevent =" handleArrowDown(cell, i, j)"
40+ @keydown.left.prevent =" handleArrowLeft(cell, i, j)"
41+ @keydown.right.prevent =" handleArrowRight(cell, i, j)"
4342 >
4443 <div >{{ cell }}</div >
4544 </td >
5251<script >
5352import IconButton from ' ./icon-button' ;
5453import { chunk } from ' ../util/base' ;
55- import { setYear } from ' ../util/date' ;
54+ import { createDate , setYear } from ' ../util/date' ;
5655import { getLocale } from ' ../locale' ;
5756
5857export default {
@@ -82,6 +81,10 @@ export default {
8281 getYearPanel: {
8382 type: Function ,
8483 },
84+ isDisabled: {
85+ type: Function ,
86+ default : () => false ,
87+ },
8588 },
8689 computed: {
8790 years () {
@@ -101,6 +104,12 @@ export default {
101104 locale () {
102105 return this .getLocale ();
103106 },
107+ refsArray () {
108+ if (this .$refs ) {
109+ return Object .entries (this .$refs );
110+ }
111+ return [];
112+ },
104113 },
105114 methods: {
106115 isDisabledArrows (type ) {
@@ -126,66 +135,64 @@ export default {
126135 }
127136 return chunk (years, 2 );
128137 },
129- handleArrowUp (row , column ) {
138+ handleArrowUp (cell , row , column ) {
130139 if (row === 0 ) {
131140 return ;
132141 }
133- const year = this .years [ row - 1 ][ column] ;
134- const ref = this .$refs [` year-cell- ${ year } ` ]? .[0 ];
142+ const refName = this .handleRefName (cell, row - 1 , column) ;
143+ const ref = this .$refs [refName ]? .[0 ];
135144 if (ref) {
136145 ref .focus ();
137- ref .classList .add (' focus' );
138146 }
139147 },
140- handleArrowDown (row , column ) {
148+ handleArrowDown (cell , row , column ) {
141149 if (row === this .years .length - 1 ) {
142150 return ;
143151 }
144- const year = this .years [ row + 1 ][ column] ;
145- const ref = this .$refs [` year-cell- ${ year } ` ]? .[0 ];
152+ const refName = this .handleRefName (cell, row + 1 , column) ;
153+ const ref = this .$refs [refName ]? .[0 ];
146154 if (ref) {
147155 ref .focus ();
148- ref .classList .add (' focus' );
149156 }
150157 },
151- handleArrowLeft (row , column ) {
152- if (column % 2 === 0 ) {
153- if (row === 0 && column === 0 ) {
154- this .handleIconDoubleLeftClick ();
155- const ref = this .$refs [` year-cell-${ this .lastYear } ` ]? .[0 ];
156- if (ref) {
157- ref .focus ();
158+ handleArrowLeft (cell , row , column ) {
159+ const currentRefName = this .handleRefName (cell, row, column);
160+ const firstRef = this .refsArray [0 ];
161+ if (currentRefName !== firstRef[0 ]) {
162+ const refName = this .handleRefName (cell, row, column - 1 );
163+ const ref = this .$refs [refName]? .[0 ];
164+ if (ref) {
165+ ref .focus ();
166+ }
167+ } else {
168+ this .handleIconDoubleLeftClick ();
169+ const lastRef = this .refsArray [this .refsArray .length - 1 ];
170+ if (lastRef .length ) {
171+ const element = lastRef[1 ];
172+ if (element .length ) {
173+ element[0 ].focus ();
158174 }
159175 }
160- return ;
161- }
162- const year = this .years [row][column - 1 ];
163- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
164- if (ref) {
165- ref .focus ();
166- ref .classList .add (' focus' );
167176 }
168177 },
169- handleArrowRight (row , column ) {
170- if (column % 2 === 1 ) {
171- if (row === this .years .length - 1 ) {
172- const lastRow = this .years [row];
173- if (column === lastRow .length - 1 ) {
174- this .handleIconDoubleRightClick ();
175- const year = this .years [0 ][0 ];
176- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
177- if (ref) {
178- ref .focus ();
179- }
178+ handleArrowRight (cell , row , column ) {
179+ const currentRefName = this .handleRefName (cell, row, column);
180+ const lastRef = this .refsArray [this .refsArray .length - 1 ];
181+ if (currentRefName !== lastRef[0 ]) {
182+ const refName = this .handleRefName (cell, row, column + 1 );
183+ const ref = this .$refs [refName]? .[0 ];
184+ if (ref) {
185+ ref .focus ();
186+ }
187+ } else {
188+ this .handleIconDoubleRightClick ();
189+ const firstRef = this .refsArray [0 ];
190+ if (firstRef .length ) {
191+ const element = firstRef[1 ];
192+ if (element .length ) {
193+ element[0 ].focus ();
180194 }
181195 }
182- return ;
183- }
184- const year = this .years [row][column + 1 ];
185- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
186- if (ref) {
187- ref .focus ();
188- ref .classList .add (' focus' );
189196 }
190197 },
191198 handleIconDoubleLeftClick () {
@@ -213,28 +220,16 @@ export default {
213220 this .selectedYear = parseInt (year, 10 );
214221 }
215222 },
216- handleRef (cellDate ) {
217- return this .disabledCalendarChanger (cellDate, ' year' ) ? undefined : ` year-cell-${ cellDate} ` ;
218- },
219- handleTabIndex (cellDate ) {
220- return this .disabledCalendarChanger (cellDate, ' year' ) ? - 1 : 0 ;
221- },
222- moveToFirstCell () {
223- const year = this .years [0 ][0 ];
224- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
225- if (ref) {
226- setTimeout (() => {
227- ref .focus ();
228- ref .classList .add (' focus' );
229- }, 1 );
223+ handleRefName (cellDate , row , col ) {
224+ const date = createDate (cellDate, 0 );
225+ if (! this .isDisabled (date)) {
226+ return ` year-cell-${ row} -${ col} ` ;
230227 }
228+ return undefined ;
231229 },
232- onBlur (i , j ) {
233- const year = this .years [i][j];
234- const ref = this .$refs [` year-cell-${ year} ` ]? .[0 ];
235- if (ref) {
236- ref .classList .remove (' focus' );
237- }
230+ handleTabIndex (cellDate ) {
231+ const date = createDate (cellDate, 0 );
232+ return this .isDisabled (date) ? - 1 : 0 ;
238233 },
239234 },
240235};
0 commit comments