Files
react-native-devtools-frontend/front_end/component_docs/data_grid_controller/basic.ts
T
Jack Franklin af59080e20 [DataGrid] Don't attempt to re-focus column headers
We were being a bit keen when trying to re-focus a data-grid row if it
had lost focus due to being removed from the DOM and then added back in.
We don't need to apply that logic if the focused cell is a header,
because they are never removed from the DOM as the user scrolls.

Fixed: chromium:1173437
Change-Id: If27cbe70a4d3f7053581d0941869c30b827f2d57
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2667508
Reviewed-by: Simon Zünd <szuend@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
2021-02-02 11:53:59 +00:00

46 lines
1.8 KiB
TypeScript

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as EnvironmentHelpers from '../../../test/unittests/front_end/helpers/EnvironmentHelpers.js';
import * as ComponentHelpers from '../../component_helpers/component_helpers.js';
import * as Components from '../../ui/components/components.js';
await EnvironmentHelpers.initializeGlobalVars();
await ComponentHelpers.ComponentServerSetup.setup();
const component = new Components.DataGridController.DataGridController();
component.data = {
columns: [
{id: 'key', title: 'Key', sortable: true, widthWeighting: 1, visible: true, hideable: false},
{id: 'value', title: 'Value', sortable: true, widthWeighting: 1, visible: true, hideable: true},
],
rows: [
// Each key is the ID of a column, and the value is the value for that column
{cells: [{columnId: 'key', value: 'Bravo', title: 'Bravo'}, {columnId: 'value', value: 'Letter B'}]},
{cells: [{columnId: 'key', value: 'Alpha', title: 'Alpha'}, {columnId: 'value', value: 'Letter A'}]},
{cells: [{columnId: 'key', value: 'Charlie', title: 'Charlie'}, {columnId: 'value', value: 'Letter C'}]},
],
};
document.getElementById('container')?.appendChild(component);
function createRandomString(): string {
let ret = '';
for (let i = 0; i < 16; i++) {
const letter = String.fromCharCode(Math.floor(65 + Math.random() * 26));
ret += letter;
}
return ret;
}
document.getElementById('add')?.addEventListener('click', () => {
const newRow = {
cells: [{columnId: 'key', value: createRandomString()}, {columnId: 'value', value: createRandomString()}],
};
component.data = {
...component.data,
rows: [...component.data.rows, newRow],
};
});