Skip to content

Commit ddc4733

Browse files
pierry01claude
andcommitted
fix(data_table): apply initial column visibility on connect in DataTableColumnToggle
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent bf60b98 commit ddc4733

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

docs/app/javascript/controllers/ruby_ui/data_table_column_visibility_controller.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
import { Controller } from "@hotwired/stimulus";
33

44
export default class extends Controller {
5+
connect() {
6+
this.element
7+
.querySelectorAll("input[type=checkbox][data-column-key]")
8+
.forEach((checkbox) =>
9+
this._apply(checkbox.dataset.columnKey, checkbox.checked)
10+
);
11+
}
12+
513
toggle(event) {
6-
const key = event.target.dataset.columnKey;
7-
const visible = event.target.checked;
14+
this._apply(event.target.dataset.columnKey, event.target.checked);
15+
}
16+
17+
_apply(key, visible) {
818
const root = this.element.closest('[data-controller~="ruby-ui--data-table"]');
919
if (!root) return;
1020
root

gem/lib/ruby_ui/data_table/data_table_column_visibility_controller.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
import { Controller } from "@hotwired/stimulus";
33

44
export default class extends Controller {
5+
connect() {
6+
this.element
7+
.querySelectorAll("input[type=checkbox][data-column-key]")
8+
.forEach((checkbox) =>
9+
this._apply(checkbox.dataset.columnKey, checkbox.checked)
10+
);
11+
}
12+
513
toggle(event) {
6-
const key = event.target.dataset.columnKey;
7-
const visible = event.target.checked;
14+
this._apply(event.target.dataset.columnKey, event.target.checked);
15+
}
16+
17+
_apply(key, visible) {
818
const root = this.element.closest('[data-controller~="ruby-ui--data-table"]');
919
if (!root) return;
1020
root

mcp/data/registry.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@
11861186
},
11871187
{
11881188
"path": "data_table_column_visibility_controller.js",
1189-
"content": "// app/javascript/controllers/ruby_ui/data_table_column_visibility_controller.js\nimport { Controller } from \"@hotwired/stimulus\";\n\nexport default class extends Controller {\n toggle(event) {\n const key = event.target.dataset.columnKey;\n const visible = event.target.checked;\n const root = this.element.closest('[data-controller~=\"ruby-ui--data-table\"]');\n if (!root) return;\n root\n .querySelectorAll(`[data-column=\"${key}\"]`)\n .forEach((el) => el.classList.toggle(\"hidden\", !visible));\n }\n}\n"
1189+
"content": "// app/javascript/controllers/ruby_ui/data_table_column_visibility_controller.js\nimport { Controller } from \"@hotwired/stimulus\";\n\nexport default class extends Controller {\n connect() {\n this.element\n .querySelectorAll(\"input[type=checkbox][data-column-key]\")\n .forEach((checkbox) =>\n this._apply(checkbox.dataset.columnKey, checkbox.checked)\n );\n }\n\n toggle(event) {\n this._apply(event.target.dataset.columnKey, event.target.checked);\n }\n\n _apply(key, visible) {\n const root = this.element.closest('[data-controller~=\"ruby-ui--data-table\"]');\n if (!root) return;\n root\n .querySelectorAll(`[data-column=\"${key}\"]`)\n .forEach((el) => el.classList.toggle(\"hidden\", !visible));\n }\n}\n"
11901190
},
11911191
{
11921192
"path": "data_table_controller.js",

0 commit comments

Comments
 (0)