|
361 | 361 | dstCell.focus();
|
362 | 362 | }
|
363 | 363 |
|
364 |
| - /** @private */ |
365 |
| - _parseEventPath(path) { |
366 |
| - const tableIndex = path.indexOf(this.$.table); |
367 |
| - return { |
368 |
| - rowGroup: path[tableIndex - 1], |
369 |
| - row: path[tableIndex - 2], |
370 |
| - cell: path[tableIndex - 3] |
371 |
| - }; |
372 |
| - } |
373 |
| - |
374 | 364 | /** @private */
|
375 | 365 | _onInteractionKeyDown(e, key) {
|
376 | 366 | const localTarget = e.composedPath()[0];
|
|
390 | 380 | break;
|
391 | 381 | }
|
392 | 382 |
|
393 |
| - const {cell} = this._parseEventPath(e.composedPath()); |
| 383 | + const {cell} = this._getGridEventLocation(e); |
394 | 384 |
|
395 |
| - if (this.interacting !== wantInteracting) { |
| 385 | + if (this.interacting !== wantInteracting && cell !== null) { |
396 | 386 | if (wantInteracting) {
|
397 | 387 | const focusTarget = cell._content.querySelector('[focus-target]') ||
|
398 | 388 | cell._content.firstElementChild;
|
|
533 | 523 |
|
534 | 524 | /** @private */
|
535 | 525 | _onCellFocusIn(e) {
|
536 |
| - const location = this._getCellFocusEventLocation(e); |
| 526 | + const {section, cell} = this._getGridEventLocation(e); |
537 | 527 | this._detectInteracting(e);
|
538 | 528 |
|
539 |
| - if (location) { |
540 |
| - const {section, cell} = location; |
| 529 | + if (section && cell) { |
541 | 530 | this._activeRowGroup = section;
|
542 | 531 | if (this.$.header === section) {
|
543 | 532 | this._headerFocusable = cell;
|
|
574 | 563 |
|
575 | 564 | /** @private */
|
576 | 565 | _detectFocusedItemIndex(e) {
|
577 |
| - const {rowGroup, row} = this._parseEventPath(e.composedPath()); |
578 |
| - if (rowGroup === this.$.items) { |
| 566 | + const {section, row} = this._getGridEventLocation(e); |
| 567 | + if (section === this.$.items) { |
579 | 568 | this._focusedItemIndex = row.index;
|
580 | 569 | }
|
581 | 570 | }
|
|
706 | 695 | }
|
707 | 696 |
|
708 | 697 | /**
|
709 |
| - * @typedef {Object} CellFocusEventLocation |
710 |
| - * @property {HTMLTableSectionElement} section - The grid section element that contains the focused cell (header, body, or footer) |
711 |
| - * @property {HTMLElement} cell - The cell element that received focus or is ancestor of the element that received focus |
| 698 | + * @typedef {Object} GridEventLocation |
| 699 | + * @property {HTMLTableSectionElement | null} section - The table section element that the event occurred in (header, body, or footer), |
| 700 | + * or null if the event did not occur in a section |
| 701 | + * @property {HTMLTableRowElement | null} row - The row element that the event occurred in, or null if the event did not occur in a row |
| 702 | + * @property {HTMLTableCellElement | null} cell - The cell element that the event occurred in, or null if the event did not occur in a |
| 703 | + * cell |
712 | 704 | * @private
|
713 | 705 | */
|
714 | 706 | /**
|
715 |
| - * Takes a focus event and returns a location object describing in which |
716 |
| - * section of the grid and in or on which cell the focus event occurred. |
717 |
| - * The focus event may either target the cell itself or contents of the cell. |
718 |
| - * If the event does not target a cell then null is returned. |
719 |
| - * @param {FocusEvent} e |
720 |
| - * @returns {CellFocusEventLocation | null} |
| 707 | + * Takes an event and returns a location object describing in which part of the grid the event occurred. |
| 708 | + * The event may either target table section, a row, a cell or contents of a cell. |
| 709 | + * @param {Event} e |
| 710 | + * @returns {GridEventLocation} |
721 | 711 | * @private
|
722 | 712 | */
|
723 |
| - _getCellFocusEventLocation(e) { |
| 713 | + _getGridEventLocation(e) { |
724 | 714 | const path = e.composedPath();
|
725 | 715 | const tableIndex = path.indexOf(this.$.table);
|
726 | 716 | // Assuming ascending path to table is: [...,] th|td, tr, thead|tbody, table [,...]
|
727 |
| - const section = tableIndex >= 2 ? path[tableIndex - 1] : null; |
| 717 | + const section = tableIndex >= 1 ? path[tableIndex - 1] : null; |
| 718 | + const row = tableIndex >= 2 ? path[tableIndex - 2] : null; |
728 | 719 | const cell = tableIndex >= 3 ? path[tableIndex - 3] : null;
|
729 | 720 |
|
730 |
| - if (!section || !cell) { |
731 |
| - return null; |
732 |
| - } |
733 |
| - |
734 | 721 | return {
|
735 | 722 | section,
|
| 723 | + row, |
736 | 724 | cell
|
737 | 725 | };
|
738 | 726 | }
|
|
0 commit comments