Skip to content

Commit b77289e

Browse files
authored
bug(data frame width): Do not allow row number column to grow with table width (#1534)
1 parent a393b49 commit b77289e

File tree

8 files changed

+29
-8
lines changed

8 files changed

+29
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
* `.update_sort(sort=)` allows app authors to programmatically update the sorting of the data frame. (#1374)
3636
* `.update_filter(filter=)` allows app authors to programmatically update the filtering of the data frame. (#1374)
3737

38-
* `@render.data_frame` now accepts both a non-`"none"` `selection_mode` value and `editable=True`. (#1454)
38+
* `@render.data_frame` now accepts both a non-`"none"` `selection_mode` value and `editable=True`. When both settings are enabled, row numbers are displayed in the first column. (#1454, #1534)
3939

4040
* `@render.data_frame`'s `<ID>.cell_selection()` no longer returns a `None` value and now always returns a dictionary containing both the `rows` and `cols` keys. This is done to achieve more consistent author code when working with cell selection. When the value's `type="none"`, both `rows` and `cols` are empty tuples. When `type="row"`, `cols` represents all column numbers of the data. In the future, when `type="col"`, `rows` will represent all row numbers of the data. These extra values are not available in `input.<ID>_cell_selection()` as they are independent of cells being selected and are removed to reduce information being sent to and from the browser. (#1376)
4141

examples/dataframe/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def app_ui(req):
2323
"row": "Single row",
2424
"rows": "Multiple rows",
2525
},
26-
selected="multiple",
26+
selected="rows",
2727
),
2828
ui.input_switch("editable", "Edit", False),
2929
ui.input_switch("filters", "Filters", True),

js/data-frame/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = ({
723723
// @ts-ignore:next-line
724724
key={header.id}
725725
colSpan={header.colSpan}
726-
style={{ width: header.getSize() }}
726+
style={{ minWidth: header.getSize() }}
727727
scope="col"
728728
tabIndex={0}
729729
onClick={header.column.getToggleSortingHandler()}

js/data-frame/styles.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ shiny-data-frame {
284284
}
285285
}
286286

287+
// When table corner is present, ensure it has a minimum width
288+
// but make sure it doesn't take up extra space
289+
shiny-data-frame .table-corner {
290+
width: 0;
291+
min-width: 25px;
292+
}
293+
287294
/*
288295
*
289296
* # CELL EDITING STYLES

shiny/www/py-shiny/data-frame/data-frame.js

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/data-frame/data-frame.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/playwright/shiny/components/data_frame/example/test_data_frame.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def test_sort(
147147
select_dataset.set("diamonds")
148148
select_dataset.expect.to_have_value("diamonds")
149149

150+
selection_mode = controller.InputSelect(page, "selection_mode")
151+
selection_mode.set("none")
152+
150153
# Table cell locators
151154
header_clarity = grid_container.locator("tr:first-child th:nth-child(4)")
152155
first_cell_clarity = grid_container.locator("tr:first-child td:nth-child(4)")
@@ -276,6 +279,8 @@ def _filter_test_impl(
276279
summary: Locator,
277280
snapshot: Any,
278281
):
282+
controller.InputSelect(page, "selection_mode").set("none")
283+
279284
filters = grid.locator("tr.filters")
280285

281286
filter_subidir_min = filters.locator("> th:nth-child(1) > div > input:nth-child(1)")

tests/playwright/shiny/components/data_frame/validate_row_selection_edit_mode/test_validate_row_selection_edit_mode.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import pytest
12
from playwright.sync_api import Page
2-
from utils.deploy_utils import skip_if_not_chrome
3+
from utils.deploy_utils import reruns, reruns_delay, skip_if_not_chrome
34

45
from shiny.playwright import controller
56
from shiny.run import ShinyAppProc
67

78

89
# Edit mode becomes flaky near end of test on CI on webkit.
910
@skip_if_not_chrome
11+
@pytest.mark.flaky(reruns=reruns, reruns_delay=reruns_delay)
1012
def test_validate_row_selection_in_edit_mode(
1113
page: Page, local_app: ShinyAppProc
1214
) -> None:
@@ -58,7 +60,9 @@ def test_validate_row_selection_in_edit_mode(
5860
data_frame._edit_cell_no_save("Temp value", row=1, col=16)
5961
page.keyboard.press("Escape")
6062
page.keyboard.press("Enter")
61-
data_frame.expect_class_state("editing", row=1, col=0)
63+
data_frame.expect_class_state(
64+
"editing", row=1, col=5
65+
) # Stage column begins to be edited.
6266

6367
# Click outside the table/Press Escape to exit row focus.
6468
# Tab to the column name, hit enter. Verify the table becomes sorted.

0 commit comments

Comments
 (0)