Commit 8bbbcd6e authored by Robert Kasza's avatar Robert Kasza Committed by Róbert Kasza
Browse files

Issue #3283314 by kaszarobert: Table widget can't be selected using Tab or Shift+Tab keys

parent 46b25408
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -77,6 +77,49 @@
                        },
                        afterCreateCol: function (index,amount) {
                          textarea.value = Papa.unparse(table.getData());
                        },
                        beforeKeyDown: function (e) {
                          // On Tab, go to external button if last cell
                          if (e.keyCode === 9 && table) {
                            let selection = table.getSelected();

                            if (typeof selection !== "undefined" && selection !== null) {
                              let rowIndex = selection[0][0];
                              let colIndex = selection[0][1];

                              if (rowIndex === (table.countRows() - 1) && colIndex === (table.countCols() - 1)) {
                                table.deselectCell();
                                e.stopPropagation();
                              }
                            }

                          }
                        }
                    });

                    renderedTableParent.addEventListener('keyup', function (e) {
                      if (e.keyCode === 9 && !e.shiftKey &&
                        (e.target.classList.contains("handsontableInput") || e.target.classList.contains("blizz")) &&
                        typeof table !== "undefined" &&
                        table !== null && typeof table.getSelected() === "undefined"
                      ) {
                        // Select the first not read-only.
                        let rowCount = table.countRows();
                        let colCount = table.countCols();

                        for (let row = 0; row < rowCount; row++) {
                          for (let col = 0; col < colCount; col++) {
                            let cellMeta = table.getCellMeta(row, col);

                            if (!cellMeta.readOnly) {
                              table.selectCell(row, col);
                              return;
                            }
                          }
                        }

                        // If no editable cells found, use the very first.
                        table.selectCell(0, 0);
                      }
                    });
                }
+43 −0
Original line number Diff line number Diff line
@@ -79,6 +79,49 @@
                        },
                        afterCreateCol: function (index, amount) {
                          textarea.value = JSON.stringify(table.getData());
                        },
                        beforeKeyDown: function (e) {
                          // On Tab, go to external button if last cell
                          if (e.keyCode === 9 && table) {
                            let selection = table.getSelected();

                            if (typeof selection !== "undefined" && selection !== null) {
                              let rowIndex = selection[0][0];
                              let colIndex = selection[0][1];

                              if (rowIndex === (table.countRows() - 1) && colIndex === (table.countCols() - 1)) {
                                table.deselectCell();
                                e.stopPropagation();
                              }
                            }

                          }
                        }
                    });

                    renderedTableParent.addEventListener('keyup', function (e) {
                      if (e.keyCode === 9 && !e.shiftKey &&
                        (e.target.classList.contains("handsontableInput") || e.target.classList.contains("blizz")) &&
                        typeof table !== "undefined" &&
                        table !== null && typeof table.getSelected() === "undefined"
                      ) {
                        // Select the first not read-only.
                        let rowCount = table.countRows();
                        let colCount = table.countCols();

                        for (let row = 0; row < rowCount; row++) {
                          for (let col = 0; col < colCount; col++) {
                            let cellMeta = table.getCellMeta(row, col);

                            if (!cellMeta.readOnly) {
                              table.selectCell(row, col);
                              return;
                            }
                          }
                        }

                        // If no editable cells found, use the very first.
                        table.selectCell(0, 0);
                      }
                    });
                }
+1 −1
Original line number Diff line number Diff line
@@ -274,7 +274,7 @@ class TableWidget extends WidgetBase implements ContainerFactoryPluginInterface

    $element['table'] = [
      '#type' => 'inline_template',
      '#template' => '<div class="rendered-table blizz format-{{ format }}" data-blizz-config="{{ config }}"></div>',
      '#template' => '<div class="rendered-table blizz format-{{ format }}" data-blizz-config="{{ config }}" tabIndex="0"></div>',
      '#context' => [
        'format' => $format,
        'config' => json_encode((object) $config),