Skip to content

Commit c003bd0

Browse files
committed
Fix #2615 - allow special characters in dash-table column IDs
1 parent eaab7f2 commit c003bd0

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

components/dash-table/src/dash-table/components/ControlledTable/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ export default class ControlledTable extends PureComponent<ControlledTableProps>
177177
active.row !== active_cell?.row)
178178
) {
179179
const target = this.$el.querySelector(
180-
`td[data-dash-row="${active_cell.row}"][data-dash-column="${active_cell.column_id}"]:not(.phantom-cell)`
180+
`td[data-dash-row="${
181+
active_cell.row
182+
}"][data-dash-column="${CSS.escape(
183+
active_cell.column_id
184+
)}"]:not(.phantom-cell)`
181185
) as HTMLElement;
182186
if (target) {
183187
target.focus();
@@ -1170,10 +1174,14 @@ export default class ControlledTable extends PureComponent<ControlledTableProps>
11701174
? table.querySelector(
11711175
`tr:nth-of-type(${
11721176
row + 1
1173-
}) th[data-dash-column="${id}"]:not(.phantom-cell)`
1177+
}) th[data-dash-column="${CSS.escape(
1178+
id
1179+
)}"]:not(.phantom-cell)`
11741180
)
11751181
: table.querySelector(
1176-
`td[data-dash-column="${id}"][data-dash-row="${row}"]:not(.phantom-cell)`
1182+
`td[data-dash-column="${CSS.escape(
1183+
id
1184+
)}"][data-dash-row="${row}"]:not(.phantom-cell)`
11771185
);
11781186

11791187
(this.refs.tooltip as TableTooltip).updateBounds(cell);

components/dash-table/tests/selenium/test_column.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,30 @@ def test_colm008_top_row_by_subset(test):
267267
for r in range(3):
268268
if target.column(c).exists(r):
269269
assert target.column(c).is_selected(r)
270+
271+
272+
def test_colm009_newline_id(test):
273+
app = dash.Dash(__name__)
274+
275+
columns = [
276+
{"name": "aaabbb", "id": "aaa\nbbb"},
277+
{"name": "cccddd", "id": "ccc\nddd"},
278+
]
279+
data = [{columns[c]["id"]: r + (3 * c) + 1 for c in [0, 1]} for r in [0, 1, 2]]
280+
tooltip_data = [{k: str(v * 11) for k, v in row.items()} for row in data]
281+
282+
app.layout = DataTable(
283+
id="table", columns=columns, data=data, tooltip_data=tooltip_data
284+
)
285+
286+
test.start_server(app)
287+
288+
target = test.table("table")
289+
cell = target.cell(1, 1)
290+
291+
target.is_ready()
292+
cell.move_to()
293+
# note first I tried tooltip.exists() and tooltip.get_text() like in ttip001
294+
# but that didn't work? didn't wait for it perhaps?
295+
test.wait_for_text_to_equal(".dash-tooltip", "55")
296+
assert test.get_log_errors() == []

dash/_jupyter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def wait_for_app():
403403
@staticmethod
404404
def _display_in_colab(dashboard_url, port, mode, width, height):
405405
# noinspection PyUnresolvedReferences
406-
from google.colab import output # pylint: disable=E0401,C0415
406+
from google.colab import output # pylint: disable=E0401,E0611,C0415
407407

408408
if mode == "inline":
409409
output.serve_kernel_port_as_iframe(port, width=width, height=height)

0 commit comments

Comments
 (0)