From 143e1b7f2818dc032c8a9bfcffb7aacaff6caee4 Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Thu, 3 Dec 2026 18:24:54 +0200 Subject: [PATCH 1/9] Page objects: test against the v2.0.0.beta2 tag Co-Authored-By: Clanker --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 603fca4..a492f25 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ group :development, :test do gem 'rspec-expectations' # Drives the dummy app in the tests of active_admin_theme/page_objects. Not on # RubyGems yet, so pinned to its tag. - gem 'active_admin_page_objects', github: 'activeadmin-plugins/active_admin_page_objects', tag: 'v2.0.0.beta1' + gem 'active_admin_page_objects', github: 'activeadmin-plugins/active_admin_page_objects', tag: 'v2.0.0.beta2' # Tests the searchable select with its None and Present filter options. Not on RubyGems, so pinned to its tag. gem 'active_admin_filter_extensions', github: 'activeadmin-plugins/active_admin_filter_extensions', tag: 'v1.3.0' end From 8142a1a2f416ab0679a658e2c85e5e2f175e2bb8 Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Thu, 3 Dec 2026 18:24:54 +0200 Subject: [PATCH 2/9] Page objects: Comments#add reveals comments in a tab Page objects 2.0.0.beta2 calls reveal_comments after the reload; the theme selects each hidden tab around the comments, outermost first, and does nothing when they already show. Co-Authored-By: Clanker --- README.md | 1 + lib/active_admin_theme/page_objects/tabs.rb | 25 +++++++++++++++++++++ test/dummy/app/admin/tabs_demo.rb | 22 ++++++++++++++++++ test/page_objects_components_test.rb | 14 ++++++++++++ test/page_objects_helper.rb | 5 +++++ 5 files changed, 67 insertions(+) diff --git a/README.md b/README.md index 5e57f2f..e2cd87b 100644 --- a/README.md +++ b/README.md @@ -752,6 +752,7 @@ The sections of active_admin_page_objects then work on theme pages. Their README - `main_menu` is the top menu on desktop and the drawer on a narrow screen, at any depth. `labels`, `has_item?` and `go` take a label path, and `current_labels` returns one. `click` hovers each parent of the top menu; in the drawer it opens the drawer and each collapsed parent first. - `ActiveAdminPageObjects::Tabs` drives the theme's `tabs`. Every page has it as `tabs`. `select`, `content`, `has_tab?` and `has_selected?` take a String, the whole title ignoring case, or a Regexp. `select_matching` is `select` for a Regexp. +- `comments.add` works when the comments sit in a tab, even a nested one: after the page reloads, it selects each tab around them. This needs active_admin_page_objects 2.0.0.beta2 or newer. - `form.field(name)` and `filters.filter(name)` return the searchable select classes for an input rendered `as: :searchable_select`. The theme registers them for that wrapper class with `register_field_class` and `register_filter_class`, so a page object that declares the base gem's `SelectField` or `SelectFilter` for such an input raises `DeclaredClassMismatch`. - `flashes` also takes `:warning`. The theme renders every flash type, while ActiveAdmin 4 drops all but `notice`, `alert` and `error`. For another type your app sets, call `ActiveAdminTheme::PageObjects.register_flash_type(:info)` in your spec helper; an unregistered type still raises `ArgumentError`. - `attributes_table.secret(key)` and `row.secret(key)` return the cell's `SecretReveal`. `has_secret_mask?(key, mask = nil)`, `has_secret_value?(key, value)` and their `has_no_` forms wait as Capybara does. diff --git a/lib/active_admin_theme/page_objects/tabs.rb b/lib/active_admin_theme/page_objects/tabs.rb index 5d553f7..ef2a87d 100644 --- a/lib/active_admin_theme/page_objects/tabs.rb +++ b/lib/active_admin_theme/page_objects/tabs.rb @@ -77,4 +77,29 @@ def tab_button(title) end end +module ActiveAdminTheme + module PageObjects + # Prepended to ActiveAdminPageObjects::Comments. Comments placed in a tab + # are hidden while another tab is selected, so Comments#add selects every + # tab around them after it reloads the page. Shown comments need nothing. + module CommentsPatch + TAB_PANELS_XPATH = "ancestor::*[@role='tabpanel']".freeze + + private + + def reveal_comments(panel) + return if panel.visible? + + # Outermost first: a nested tab's button is hidden until its parent tab shows. + panel.all(:xpath, TAB_PANELS_XPATH, visible: :all, wait: false).each do |tab_panel| + next if tab_panel.visible? + + panel.session.find(:css, "[role='tab'][aria-controls='#{tab_panel[:id]}']").click + end + end + end + end +end + ActiveAdminPageObjects::Tabs.prepend(ActiveAdminTheme::PageObjects::TabsPatch) +ActiveAdminPageObjects::Comments.prepend(ActiveAdminTheme::PageObjects::CommentsPatch) diff --git a/test/dummy/app/admin/tabs_demo.rb b/test/dummy/app/admin/tabs_demo.rb index 4bc84d6..70520ce 100644 --- a/test/dummy/app/admin/tabs_demo.rb +++ b/test/dummy/app/admin/tabs_demo.rb @@ -19,3 +19,25 @@ end end end + +# Comments markup in a tab of a nested tab, for the page objects' reveal_comments +# (test/page_objects_components_test.rb). The dummy has no comments table. +ActiveAdmin.register_page "Tabbed comments" do + menu false + + content do + tabs do + tab("Details") { para "Details" } + tab("History") do + tabs do + tab("Changes") { para "Changes" } + tab("Notes") do + div id: "active-admin-comments-form" do + para "A comment", class: "tabbed-comment" + end + end + end + end + end + end +end diff --git a/test/page_objects_components_test.rb b/test/page_objects_components_test.rb index 9e9e1b9..8038867 100644 --- a/test/page_objects_components_test.rb +++ b/test/page_objects_components_test.rb @@ -288,6 +288,20 @@ def test_confirm_dialog_submits_with_its_method assert_equal "Suspend customer", dialogs.confirm_dialog(dialog: "action-confirm").trigger_text end + def test_comments_in_a_nested_tab_are_revealed_and_shown_ones_are_left_alone + page_object = Pages::TabbedComments.new + page_object.load + panel = find("#active-admin-comments-form", visible: :all) + refute panel.visible? + comments = page_object.comments(visible: :all) + comments.send(:reveal_comments, panel) + assert_selector "#active-admin-comments-form .tabbed-comment", visible: :visible + + page.execute_script("window.tabClicks = 0; document.addEventListener('click', (e) => { if (e.target.closest('[role=tab]')) window.tabClicks++ })") + comments.send(:reveal_comments, find("#active-admin-comments-form")) + assert_equal 0, page.evaluate_script("window.tabClicks") + end + def test_confirm_dialog_waits_for_its_buttons_to_be_enabled dialogs = Pages::ConfirmDialogs.new dialogs.load diff --git a/test/page_objects_helper.rb b/test/page_objects_helper.rb index 5fd2f5e..eaf63ab 100644 --- a/test/page_objects_helper.rb +++ b/test/page_objects_helper.rb @@ -108,6 +108,11 @@ class ConfirmDialogs < PO::Page class ColumnsDemo < PO::Page set_url "/admin/columns" end + + class TabbedComments < PO::Page + set_url "/admin/tabbed_comments" + section :comments, PO::Comments + end end class PageObjectsTestCase < Minitest::Test From 10723d30d13a267c98fb3e6850f4d93737214431 Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Thu, 3 Dec 2026 18:28:40 +0200 Subject: [PATCH 3/9] Sticky index table header The first header row of an index table stays under the top bar from 768px up, as in v3. ActiveAdminTheme.sticky_table_header turns it off, and skip-sticky-headers and with-sticky-headers keep the v3 classes. A with-sticky-headers table in a panel or tab widens the page instead of scrolling inside its box, which would hold the header. Co-Authored-By: Clanker --- README.md | 21 ++++++++++ app/tailwind/active_admin_theme.css | 42 +++++++++++++++---- app/views/active_admin/_page_content.html.erb | 2 +- lib/active_admin_theme.rb | 8 +++- test/dummy/app/admin/wide_table.rb | 12 ++++-- test/layout_test.rb | 31 ++++++++++++++ 6 files changed, 102 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e2cd87b..5c46259 100644 --- a/README.md +++ b/README.md @@ -496,6 +496,27 @@ end `group_headings:` on the sidebar decides whether each group gets a heading and its own list. The default, `:auto`, shows headings only when there is more than one group and more than five links, so a short sidebar stays one plain list. `true` always shows them and `false` never does; without headings the links form one list in the order they were declared. A group whose links are all left out disappears with them. The titles are "Related records" and "External links", from `active_admin_theme.sidebars.related_records` and `.external_links`, or from `title:`. +### Sticky table header + +From 768px up, the first header row of an index table stays under the top bar while the page scrolls. To turn it off everywhere, set this in an initializer: + +```ruby +ActiveAdminTheme.sticky_table_header = false +``` + +To turn it off for one index, add the `skip-sticky-headers` class. Another table opts in with the `with-sticky-headers` class. Such a table in a panel or a tab widens the page, as an index table does, instead of scrolling inside its box: + +```ruby +index do |table| + table.add_class "skip-sticky-headers" + # columns +end + +table_for orders, class: "with-sticky-headers" do + # columns +end +``` + ### Sticky first column Add the `with-sticky-rows` class to a wide table, and its first column stays in place while the table scrolls sideways: diff --git a/app/tailwind/active_admin_theme.css b/app/tailwind/active_admin_theme.css index 504c39c..10f83f2 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -176,24 +176,24 @@ .data-table :where(tbody > tr.selected) > td { background-color: var(--aat-selected-row); } -/* A wide index table widens the page, and the window scrolls sideways, as in - * v3. The main column takes the table's width, and the bars around the +/* A wide index table, or a table with with-sticky-headers, widens the page, + * and the window scrolls sideways, as in v3. The main column takes the table's width, and the bars around the * content stay at the viewport width. layout.js sets --aat-viewport-width, * which leaves out a classic scrollbar. Below 768px the table scrolls in its * wrapper. */ @media (width >= 48rem) { - :has(> [data-aat-page] .index-as-table) { + :has(> [data-aat-page] :is(.index-as-table, table.with-sticky-headers)) { min-width: fit-content; } - :has(> [data-aat-page] .index-as-table) > :not([data-aat-page], #main-menu, script) { + :has(> [data-aat-page] :is(.index-as-table, table.with-sticky-headers)) > :not([data-aat-page], #main-menu, script) { position: sticky; inset-inline-start: 0; width: var(--aat-viewport-width, 100vw); } - [data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(.index-as-table) { + [data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(:is(.index-as-table, table.with-sticky-headers)) { grid-template-columns: 270px minmax(min-content, 1fr); } - [data-aat-page]:is(:not([data-aat-has-sidebar]), [data-aat-sidebar-collapsed]):has(.index-as-table) { + [data-aat-page]:is(:not([data-aat-has-sidebar]), [data-aat-sidebar-collapsed]):has(:is(.index-as-table, table.with-sticky-headers)) { grid-template-columns: minmax(min-content, 1fr); } [data-aat-page] :is(.index-as-table, .paginated-collection-contents:has(> .index-as-table)) { @@ -201,11 +201,35 @@ } } -/* A table_for in a panel or a tab scrolls sideways instead of widening the page. */ -.panel-body:has(> .data-table), -.aat-tab-panel:has(> .data-table) { +/* A table_for in a panel or a tab scrolls sideways instead of widening the + * page, unless it has a sticky header, which a scrolling box would hold. */ +.panel-body:has(> .data-table:not(.with-sticky-headers)), +.aat-tab-panel:has(> .data-table:not(.with-sticky-headers)) { overflow-x: auto; } +/* The first header row of an index table stays under the top bar while the + * page scrolls (ActiveAdminTheme.sticky_table_header). As in v3, an index + * opts out with skip-sticky-headers and another table opts in with + * with-sticky-headers. A shadow draws the bottom line, which a sticky cell's + * collapsed border would leave behind. Below 768px the table scrolls in its + * wrapper, which a sticky header cannot leave. */ +@media (width >= 48rem) { + [data-aat-sticky-thead] .index-as-table .data-table:not(.skip-sticky-headers) > thead > tr:first-child > th, + table.with-sticky-headers > thead > tr:first-child > th { + position: sticky; + top: var(--aa-header-height); + z-index: 2; + box-shadow: inset 0 -1px 0 var(--aat-border); + } + table.with-sticky-headers > thead > tr > th { + background-color: var(--aat-table-header); + } + :is([data-aat-sticky-thead] .index-as-table .data-table:not(.skip-sticky-headers), table.with-sticky-headers).with-sticky-rows > thead > tr:first-child > th:first-child { + z-index: 3; + box-shadow: inset -1px 0 0 var(--aat-border), inset 0 -1px 0 var(--aat-border); + } +} + /* Opt-in sticky first column. Body cells keep the stripe, hover and selected fills above. */ table.with-sticky-rows :is(td, th):first-child { position: sticky; diff --git a/app/views/active_admin/_page_content.html.erb b/app/views/active_admin/_page_content.html.erb index 226b481..601b6da 100644 --- a/app/views/active_admin/_page_content.html.erb +++ b/app/views/active_admin/_page_content.html.erb @@ -1,6 +1,6 @@ <%= active_admin_theme_config_tag %> <% has_sidebar = !(skip_sidebar? || sidebar_sections_for_action.blank?) %> -
class="px-2.5 md:px-4 grid grid-cols-1 gap-3 md:gap-4 md:data-aat-has-sidebar:grid-cols-[270px_minmax(0,1fr)] md:data-aat-sidebar-collapsed:grid-cols-1"> +
<%= "data-aat-sticky-thead" if ActiveAdminTheme.sticky_table_header %> class="px-2.5 md:px-4 grid grid-cols-1 gap-3 md:gap-4 md:data-aat-has-sidebar:grid-cols-[270px_minmax(0,1fr)] md:data-aat-sidebar-collapsed:grid-cols-1"> <%= render "active_admin/sidebar" %>
<% if has_sidebar %> diff --git a/lib/active_admin_theme.rb b/lib/active_admin_theme.rb index 7c22217..ddcabcb 100644 --- a/lib/active_admin_theme.rb +++ b/lib/active_admin_theme.rb @@ -35,7 +35,7 @@ class << self # Page size of a searchable_select_options endpoint that declares no per_page:. Nil means 50. attr_accessor :searchable_select_per_page - attr_writer :javascripts, :searchable_select_all, :searchable_select_min_chars + attr_writer :javascripts, :searchable_select_all, :searchable_select_min_chars, :sticky_table_header # nil keeps ActiveAdmin's "Powered by" footer; any of the three replaces it. # footer_extra and site_title_link are a String, or a Proc run in the view. # site_title_link false or nil leaves the title as plain text. @@ -51,6 +51,12 @@ def searchable_select_all @searchable_select_all.nil? ? true : @searchable_select_all end + # True when the header row of an index table stays under the top bar while + # the page scrolls, from 768px up. False turns it off. + def sticky_table_header + @sticky_table_header.nil? ? true : @sticky_table_header + end + # Characters to type before a searchable select asks its endpoint. def searchable_select_min_chars @searchable_select_min_chars || 3 diff --git a/test/dummy/app/admin/wide_table.rb b/test/dummy/app/admin/wide_table.rb index 781d8e8..ae2e8c5 100644 --- a/test/dummy/app/admin/wide_table.rb +++ b/test/dummy/app/admin/wide_table.rb @@ -31,12 +31,18 @@ "" + row.map { |cell| "#{ERB::Util.html_escape(cell)}" }.join + "" end.join text_node( - # with-sticky-headers: the one place in the repo's test surface where - # the sticky-thead selector matches a real element (AA's own index - # tables need a database-backed resource the dummy doesn't have). + # with-sticky-headers: a table outside an index opts in to the sticky + # header row (test/layout_test.rb). (%() + head + "" + body + "
") .html_safe ) end + + panel "A table_for with a sticky header" do + table_for (1..30).to_a, class: "with-sticky-headers", id: "sticky-table-for" do + column("Row") { |n| "Row #{n}" } + column("Value") { |n| "Value #{n}" } + end + end end end diff --git a/test/layout_test.rb b/test/layout_test.rb index 69ffce2..ce90c98 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -168,6 +168,37 @@ def test_wide_table_outside_an_index_keeps_its_own_scroll assert_operator page.evaluate_script("document.documentElement.scrollWidth"), :<=, 1100 end + def test_index_table_header_sticks_under_the_top_bar + page.current_window.resize_to(1280, 500) + visit "/admin/customers" + assert_selector "[data-aat-sticky-thead]" + th = "document.querySelector('.data-table thead th').getBoundingClientRect().top" + page.execute_script("window.scrollTo(0, 600)") + assert_in_delta 40, page.evaluate_script(th), 1 + + visit "/admin/wide_table" + page.execute_script("window.scrollTo(0, 600)") + assert_in_delta 40, page.evaluate_script("document.querySelector('table.wide-demo thead th').getBoundingClientRect().top"), 1 + # A table_for in a panel: the panel stops scrolling on its own, which would hold the header. + page.execute_script("const t = document.getElementById('sticky-table-for'); window.scrollTo({top: t.getBoundingClientRect().top + window.scrollY + 200, behavior: 'instant'})") + assert_in_delta 40, page.evaluate_script("document.querySelector('#sticky-table-for thead th').getBoundingClientRect().top"), 1 + assert_equal "visible", page.evaluate_script("getComputedStyle(document.getElementById('sticky-table-for').parentElement).overflowX") + + page.current_window.resize_to(700, 500) + visit "/admin/customers" + assert_equal "static", page.evaluate_script("getComputedStyle(document.querySelector('.data-table thead th')).position") + end + + def test_index_table_header_can_be_turned_off + ActiveAdminTheme.sticky_table_header = false + visit "/admin/customers" + assert_selector "[data-aat-page]" + assert_no_selector "[data-aat-sticky-thead]" + assert_equal "static", page.evaluate_script("getComputedStyle(document.querySelector('.data-table thead th')).position") + ensure + ActiveAdminTheme.sticky_table_header = nil + end + def test_wide_index_tables_scroll_inside_their_wrapper_not_the_page page.current_window.resize_to(390, 800) visit "/admin/customers" From 4fdc83b73c68ffffa98a1c9ad7a4737bc9532a61 Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Thu, 3 Dec 2026 18:53:31 +0200 Subject: [PATCH 4/9] Sticky header: leave tables in panels and tabs alone A panel or a tab scrolls sideways on its own, as in beta2, so with-sticky-headers does nothing there and the page does not widen. Co-Authored-By: Clanker --- README.md | 8 +++----- app/tailwind/active_admin_theme.css | 32 ++++++++++++++--------------- test/dummy/app/admin/wide_table.rb | 6 +++--- test/layout_test.rb | 9 ++++---- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 5c46259..7177f30 100644 --- a/README.md +++ b/README.md @@ -504,19 +504,17 @@ From 768px up, the first header row of an index table stays under the top bar wh ActiveAdminTheme.sticky_table_header = false ``` -To turn it off for one index, add the `skip-sticky-headers` class. Another table opts in with the `with-sticky-headers` class. Such a table in a panel or a tab widens the page, as an index table does, instead of scrolling inside its box: +To turn it off for one index, add the `skip-sticky-headers` class: ```ruby index do |table| table.add_class "skip-sticky-headers" # columns end - -table_for orders, class: "with-sticky-headers" do - # columns -end ``` +A table outside a panel or a tab opts in with the `with-sticky-headers` class, as in v3. A panel or a tab scrolls sideways on its own, so the class does nothing there. + ### Sticky first column Add the `with-sticky-rows` class to a wide table, and its first column stays in place while the table scrolls sideways: diff --git a/app/tailwind/active_admin_theme.css b/app/tailwind/active_admin_theme.css index 10f83f2..fb98fbe 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -176,24 +176,24 @@ .data-table :where(tbody > tr.selected) > td { background-color: var(--aat-selected-row); } -/* A wide index table, or a table with with-sticky-headers, widens the page, - * and the window scrolls sideways, as in v3. The main column takes the table's width, and the bars around the +/* A wide index table widens the page, and the window scrolls sideways, as in + * v3. The main column takes the table's width, and the bars around the * content stay at the viewport width. layout.js sets --aat-viewport-width, * which leaves out a classic scrollbar. Below 768px the table scrolls in its * wrapper. */ @media (width >= 48rem) { - :has(> [data-aat-page] :is(.index-as-table, table.with-sticky-headers)) { + :has(> [data-aat-page] .index-as-table) { min-width: fit-content; } - :has(> [data-aat-page] :is(.index-as-table, table.with-sticky-headers)) > :not([data-aat-page], #main-menu, script) { + :has(> [data-aat-page] .index-as-table) > :not([data-aat-page], #main-menu, script) { position: sticky; inset-inline-start: 0; width: var(--aat-viewport-width, 100vw); } - [data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(:is(.index-as-table, table.with-sticky-headers)) { + [data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(.index-as-table) { grid-template-columns: 270px minmax(min-content, 1fr); } - [data-aat-page]:is(:not([data-aat-has-sidebar]), [data-aat-sidebar-collapsed]):has(:is(.index-as-table, table.with-sticky-headers)) { + [data-aat-page]:is(:not([data-aat-has-sidebar]), [data-aat-sidebar-collapsed]):has(.index-as-table) { grid-template-columns: minmax(min-content, 1fr); } [data-aat-page] :is(.index-as-table, .paginated-collection-contents:has(> .index-as-table)) { @@ -201,30 +201,30 @@ } } -/* A table_for in a panel or a tab scrolls sideways instead of widening the - * page, unless it has a sticky header, which a scrolling box would hold. */ -.panel-body:has(> .data-table:not(.with-sticky-headers)), -.aat-tab-panel:has(> .data-table:not(.with-sticky-headers)) { +/* A table_for in a panel or a tab scrolls sideways instead of widening the page. */ +.panel-body:has(> .data-table), +.aat-tab-panel:has(> .data-table) { overflow-x: auto; } /* The first header row of an index table stays under the top bar while the * page scrolls (ActiveAdminTheme.sticky_table_header). As in v3, an index * opts out with skip-sticky-headers and another table opts in with - * with-sticky-headers. A shadow draws the bottom line, which a sticky cell's - * collapsed border would leave behind. Below 768px the table scrolls in its - * wrapper, which a sticky header cannot leave. */ + * with-sticky-headers, except in a panel or a tab, which scrolls on its own. + * A shadow draws the bottom line, which a sticky cell's collapsed border + * would leave behind. Below 768px the table scrolls in its wrapper, which a + * sticky header cannot leave. */ @media (width >= 48rem) { [data-aat-sticky-thead] .index-as-table .data-table:not(.skip-sticky-headers) > thead > tr:first-child > th, - table.with-sticky-headers > thead > tr:first-child > th { + table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table) > thead > tr:first-child > th { position: sticky; top: var(--aa-header-height); z-index: 2; box-shadow: inset 0 -1px 0 var(--aat-border); } - table.with-sticky-headers > thead > tr > th { + table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table) > thead > tr:first-child > th { background-color: var(--aat-table-header); } - :is([data-aat-sticky-thead] .index-as-table .data-table:not(.skip-sticky-headers), table.with-sticky-headers).with-sticky-rows > thead > tr:first-child > th:first-child { + :is([data-aat-sticky-thead] .index-as-table .data-table:not(.skip-sticky-headers), table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table)).with-sticky-rows > thead > tr:first-child > th:first-child { z-index: 3; box-shadow: inset -1px 0 0 var(--aat-border), inset 0 -1px 0 var(--aat-border); } diff --git a/test/dummy/app/admin/wide_table.rb b/test/dummy/app/admin/wide_table.rb index ae2e8c5..b0352eb 100644 --- a/test/dummy/app/admin/wide_table.rb +++ b/test/dummy/app/admin/wide_table.rb @@ -31,14 +31,14 @@ "" + row.map { |cell| "#{ERB::Util.html_escape(cell)}" }.join + "" end.join text_node( - # with-sticky-headers: a table outside an index opts in to the sticky - # header row (test/layout_test.rb). + # with-sticky-headers does nothing in a panel: the header scrolls away + # (test/layout_test.rb). (%() + head + "" + body + "
") .html_safe ) end - panel "A table_for with a sticky header" do + panel "A table_for with with-sticky-headers, which a panel ignores" do table_for (1..30).to_a, class: "with-sticky-headers", id: "sticky-table-for" do column("Row") { |n| "Row #{n}" } column("Value") { |n| "Value #{n}" } diff --git a/test/layout_test.rb b/test/layout_test.rb index ce90c98..fba6536 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -176,13 +176,12 @@ def test_index_table_header_sticks_under_the_top_bar page.execute_script("window.scrollTo(0, 600)") assert_in_delta 40, page.evaluate_script(th), 1 + # A panel scrolls on its own, so with-sticky-headers in it does nothing. visit "/admin/wide_table" - page.execute_script("window.scrollTo(0, 600)") - assert_in_delta 40, page.evaluate_script("document.querySelector('table.wide-demo thead th').getBoundingClientRect().top"), 1 - # A table_for in a panel: the panel stops scrolling on its own, which would hold the header. page.execute_script("const t = document.getElementById('sticky-table-for'); window.scrollTo({top: t.getBoundingClientRect().top + window.scrollY + 200, behavior: 'instant'})") - assert_in_delta 40, page.evaluate_script("document.querySelector('#sticky-table-for thead th').getBoundingClientRect().top"), 1 - assert_equal "visible", page.evaluate_script("getComputedStyle(document.getElementById('sticky-table-for').parentElement).overflowX") + assert_equal "static", page.evaluate_script("getComputedStyle(document.querySelector('#sticky-table-for thead th')).position") + assert_equal "auto", page.evaluate_script("getComputedStyle(document.getElementById('sticky-table-for').parentElement).overflowX") + assert_equal "static", page.evaluate_script("getComputedStyle(document.querySelector('table.wide-demo thead th')).position") page.current_window.resize_to(700, 500) visit "/admin/customers" From ffe94e420f3e1956ee763317e96e03b60bb4ba83 Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Thu, 3 Dec 2026 19:10:35 +0200 Subject: [PATCH 5/9] Index title bar dropdowns take clicks over the toolbar On a wide-table index the title bar is sticky, which makes it a stacking context with z-index auto, so the toolbar below took the clicks meant for its dropdown items. Regression from 4.0.0.beta2. Co-Authored-By: Clanker --- app/tailwind/active_admin_theme.css | 7 +++++-- test/dummy/app/admin/menu_orders.rb | 24 ++++++++++++++++++++++++ test/layout_test.rb | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/dummy/app/admin/menu_orders.rb diff --git a/app/tailwind/active_admin_theme.css b/app/tailwind/active_admin_theme.css index fb98fbe..8591e53 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -179,8 +179,10 @@ /* A wide index table widens the page, and the window scrolls sideways, as in * v3. The main column takes the table's width, and the bars around the * content stay at the viewport width. layout.js sets --aat-viewport-width, - * which leaves out a classic scrollbar. Below 768px the table scrolls in its - * wrapper. */ + * which leaves out a classic scrollbar. A sticky bar is a stacking context: + * its z-index keeps the title bar's dropdowns above the page content and its + * sticky header row, and below #site-header. Below 768px the table scrolls in + * its wrapper. */ @media (width >= 48rem) { :has(> [data-aat-page] .index-as-table) { min-width: fit-content; @@ -188,6 +190,7 @@ :has(> [data-aat-page] .index-as-table) > :not([data-aat-page], #main-menu, script) { position: sticky; inset-inline-start: 0; + z-index: 10; width: var(--aat-viewport-width, 100vw); } [data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(.index-as-table) { diff --git a/test/dummy/app/admin/menu_orders.rb b/test/dummy/app/admin/menu_orders.rb new file mode 100644 index 0000000..f02c25b --- /dev/null +++ b/test/dummy/app/admin/menu_orders.rb @@ -0,0 +1,24 @@ +# An index with an action-item dropdown whose items hang over the table +# toolbar, which the batch actions render (test/layout_test.rb). +ActiveAdmin.register Order, as: "MenuOrder" do + menu false + config.batch_actions = true + + filter :status, as: :select, collection: Order::STATUSES + + action_item :new_export, only: :index do + dropdown_menu_tag "New export", id: "new-export" do + item "CSV", "/admin/dropdown_menu/echo?to=csv" + item "XML", "/admin/dropdown_menu/echo?to=xml" + item "JSON", "/admin/dropdown_menu/echo?to=json" + item "PDF", "/admin/dropdown_menu/echo?to=pdf" + end + end + + index do + selectable_column + id_column + column :reference + column :status + end +end diff --git a/test/layout_test.rb b/test/layout_test.rb index fba6536..0423f30 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -168,6 +168,22 @@ def test_wide_table_outside_an_index_keeps_its_own_scroll assert_operator page.evaluate_script("document.documentElement.scrollWidth"), :<=, 1100 end + def test_action_item_dropdown_items_take_clicks_over_the_index_toolbar + page.current_window.resize_to(1280, 800) + visit "/admin/menu_orders" + find("button", text: "New export").click + hits = page.evaluate_script(<<~JS) + [...document.querySelectorAll("#new-export a, [data-test-action-items] a[href*='to=']")].filter((a) => a.offsetParent).map((a) => { + const box = a.getBoundingClientRect() + const hit = document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2) + return a.contains(hit) ? a.textContent.trim() : hit.className + }) + JS + assert_equal %w[CSV XML JSON PDF], hits + find("a[href$='to=xml']").click + assert_text "xml" + end + def test_index_table_header_sticks_under_the_top_bar page.current_window.resize_to(1280, 500) visit "/admin/customers" From 77c44e24bfea6bb82d0e2516f83b83d0437839c6 Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Thu, 3 Dec 2026 18:56:24 +0200 Subject: [PATCH 6/9] Row click ticks the batch checkbox ActiveAdmin 4 colors a row as selected only from the select-all box, so a checked box now colors its own row. row_click_selects = false keeps v3. Co-Authored-By: Clanker --- README.md | 10 +++++ .../active_admin_theme/table_crisscross.js | 8 ++-- app/tailwind/active_admin_theme.css | 4 +- app/views/active_admin/_page_content.html.erb | 2 +- docs/migrating-from-v3.md | 2 +- lib/active_admin_theme.rb | 9 ++++- test/layout_test.rb | 38 ++++++++++++++++++- 7 files changed, 63 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7177f30..10aef00 100644 --- a/README.md +++ b/README.md @@ -515,6 +515,16 @@ end A table outside a panel or a tab opts in with the `with-sticky-headers` class, as in v3. A panel or a tab scrolls sideways on its own, so the class does nothing there. +### Row click + +A click on an index row ticks its batch checkbox, as in ActiveAdmin 4, and a row with a checked box is highlighted. The click also highlights the row and column of the cell. To keep the v3 behavior, where the click only highlights, set this in an initializer: + +```ruby +ActiveAdminTheme.row_click_selects = false +``` + +The setting needs the `active_admin_theme/table_crisscross` script, which is on by default. + ### Sticky first column Add the `with-sticky-rows` class to a wide table, and its first column stays in place while the table scrolls sideways: diff --git a/app/javascript/active_admin_theme/table_crisscross.js b/app/javascript/active_admin_theme/table_crisscross.js index 337b747..9a17266 100644 --- a/app/javascript/active_admin_theme/table_crisscross.js +++ b/app/javascript/active_admin_theme/table_crisscross.js @@ -2,9 +2,9 @@ // column with data-selected, so a value in a wide table is easy to trace to its // headers. The clicked cell gets data-selected-cell. // -// ActiveAdmin ticks a row's checkbox when any cell is clicked; the handler -// clicks it again to undo that, so highlighting never leaves rows selected for -// batch actions. +// ActiveAdmin ticks a row's checkbox when any cell is clicked. When +// ActiveAdminTheme.row_click_selects is false, the handler clicks it again to +// undo that, so highlighting never leaves rows selected for batch actions. const MARK = "data-selected" const CENTER = "data-selected-cell" @@ -21,7 +21,7 @@ document.addEventListener("click", (event) => { // ActiveAdmin's row toggler has already handled this click; revert it. const checkbox = row.querySelector("input[type=checkbox]") - if (checkbox) checkbox.click() + if (checkbox && !cell.closest("[data-aat-row-click-selects]")) checkbox.click() clear(table) const index = cell.cellIndex diff --git a/app/tailwind/active_admin_theme.css b/app/tailwind/active_admin_theme.css index 8591e53..c26c6f6 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -173,7 +173,9 @@ .data-table :where(tbody > tr):hover > td { background-color: var(--aat-surface-hover); } -.data-table :where(tbody > tr.selected) > td { +/* ActiveAdmin 4 marks rows selected only from the select-all box, so a + * checked batch checkbox marks its own row. */ +.data-table :where(tbody > tr.selected, tbody > tr:has(.batch-actions-resource-selection:checked)) > td { background-color: var(--aat-selected-row); } /* A wide index table widens the page, and the window scrolls sideways, as in diff --git a/app/views/active_admin/_page_content.html.erb b/app/views/active_admin/_page_content.html.erb index 601b6da..d145888 100644 --- a/app/views/active_admin/_page_content.html.erb +++ b/app/views/active_admin/_page_content.html.erb @@ -1,6 +1,6 @@ <%= active_admin_theme_config_tag %> <% has_sidebar = !(skip_sidebar? || sidebar_sections_for_action.blank?) %> -
<%= "data-aat-sticky-thead" if ActiveAdminTheme.sticky_table_header %> class="px-2.5 md:px-4 grid grid-cols-1 gap-3 md:gap-4 md:data-aat-has-sidebar:grid-cols-[270px_minmax(0,1fr)] md:data-aat-sidebar-collapsed:grid-cols-1"> +
<%= "data-aat-sticky-thead" if ActiveAdminTheme.sticky_table_header %> <%= "data-aat-row-click-selects" if ActiveAdminTheme.row_click_selects %> class="px-2.5 md:px-4 grid grid-cols-1 gap-3 md:gap-4 md:data-aat-has-sidebar:grid-cols-[270px_minmax(0,1fr)] md:data-aat-sidebar-collapsed:grid-cols-1"> <%= render "active_admin/sidebar" %>
<% if has_sidebar %> diff --git a/docs/migrating-from-v3.md b/docs/migrating-from-v3.md index 76c7cc2..870d221 100644 --- a/docs/migrating-from-v3.md +++ b/docs/migrating-from-v3.md @@ -57,7 +57,7 @@ ActiveAdmin 4 dropped menus deeper than one submenu level, but the theme keeps t - The theme loads as ES modules through `ActiveAdmin.importmap`, not through Sprockets. A pin in your own `config/importmap.rb` does not load on ActiveAdmin pages; pin your scripts into `ActiveAdmin.importmap` (README, "JavaScript"). - `theme_toggle.js` is rewritten as `active_admin_theme/theme_toggle`. The header switch cycles auto, light and dark, and keeps ActiveAdmin 4's `theme` key in `localStorage`, so a choice made in theme 3 is not carried over. - `scrollbar_width.js` is gone. The header no longer uses `100vw`, so it is not needed. -- `table_crisscross.js` is rewritten without jQuery as `active_admin_theme/table_crisscross`, and loads by default. The `td.selected` marker is now `td[data-selected]`. +- `table_crisscross.js` is rewritten without jQuery as `active_admin_theme/table_crisscross`, and loads by default. The `td.selected` marker is now `td[data-selected]`. A cell click now also ticks the row's batch checkbox; `ActiveAdminTheme.row_click_selects = false` restores the v3 behavior. - `server_clock.js` is rewritten as `active_admin_theme/server_clock`. It reads `data-servertime-epoch` and `data-servertime-zone` from `[data-server-clock]`; the old `data-servertime` wall-clock format is not supported. ## DSL diff --git a/lib/active_admin_theme.rb b/lib/active_admin_theme.rb index ddcabcb..90f81ad 100644 --- a/lib/active_admin_theme.rb +++ b/lib/active_admin_theme.rb @@ -35,7 +35,8 @@ class << self # Page size of a searchable_select_options endpoint that declares no per_page:. Nil means 50. attr_accessor :searchable_select_per_page - attr_writer :javascripts, :searchable_select_all, :searchable_select_min_chars, :sticky_table_header + attr_writer :javascripts, :searchable_select_all, :searchable_select_min_chars, :sticky_table_header, + :row_click_selects # nil keeps ActiveAdmin's "Powered by" footer; any of the three replaces it. # footer_extra and site_title_link are a String, or a Proc run in the view. # site_title_link false or nil leaves the title as plain text. @@ -57,6 +58,12 @@ def sticky_table_header @sticky_table_header.nil? ? true : @sticky_table_header end + # True when a click on an index row ticks its batch checkbox, as in + # ActiveAdmin 4. False keeps the v3 behavior: the click only highlights. + def row_click_selects + @row_click_selects.nil? ? true : @row_click_selects + end + # Characters to type before a searchable select asks its endpoint. def searchable_select_min_chars @searchable_select_min_chars || 3 diff --git a/test/layout_test.rb b/test/layout_test.rb index 0423f30..135b1a0 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -273,13 +273,47 @@ def test_action_items_are_buttons refute_equal "rgba(0, 0, 0, 0)", background end - def test_crisscross_marks_row_and_column + def test_crisscross_marks_row_and_column_and_the_row_click_ticks_its_checkbox visit "/admin/customers" cells = all("table.data-table tbody tr:nth-child(2) td") cells[3].click assert_selector "table.data-table td[data-selected-cell]", count: 1 assert_selector "table.data-table tbody td[data-selected]", minimum: 30 - assert_no_selector "table.data-table tbody tr.selected" + assert find("table.data-table tbody tr:nth-child(2) input[type=checkbox]").checked? + cells[3].click + refute find("table.data-table tbody tr:nth-child(2) input[type=checkbox]").checked? + end + + def test_a_checked_row_is_highlighted + visit "/admin/customers" + checkbox = find("table.data-table tbody tr:nth-child(2) input[type=checkbox]") + refute_equal selected_row_color, row_color(3) + checkbox.click + find("[data-test-page-header] h2").hover # a hovered row shows the hover color + assert_equal selected_row_color, row_color(3) + checkbox.click + find("[data-test-page-header] h2").hover + refute_equal selected_row_color, row_color(3) + end + + def selected_row_color + page.evaluate_script("(() => { const d = document.createElement('div'); d.style.color = 'var(--aat-selected-row)'; document.body.append(d); const c = getComputedStyle(d).color; d.remove(); return c })()") + end + + # The background of row 2's cell +index+. + def row_color(index) + page.evaluate_script("getComputedStyle(document.querySelectorAll('table.data-table tbody tr:nth-child(2) td')[#{index}]).backgroundColor") + end + + def test_row_click_selects_can_be_turned_off + ActiveAdminTheme.row_click_selects = false + visit "/admin/customers" + assert_selector "[data-aat-page]" + all("table.data-table tbody tr:nth-child(2) td")[3].click + assert_selector "table.data-table td[data-selected-cell]", count: 1 + refute find("table.data-table tbody tr:nth-child(2) input[type=checkbox]").checked? + ensure + ActiveAdminTheme.row_click_selects = nil end def test_tabs_switch_panels From 897151661f73b3d89dd5e987376683b32cfdddeb Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Thu, 3 Dec 2026 20:53:40 +0200 Subject: [PATCH 7/9] Release 4.0.0.beta3 Co-Authored-By: Clanker --- README.md | 4 ++-- docs/migrating-from-v3.md | 2 +- lib/active_admin_theme/version.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 10aef00..00da90f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Theme 4 needs ActiveAdmin 4 (`>= 4.0.0.beta23`) and Ruby 3.3 or newer. To upgrad | ActiveAdmin | Theme | Install | Docs | | --- | --- | --- | --- | -| 4 | 4.0.0.beta2 | `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta2"` | this README | +| 4 | 4.0.0.beta3 | `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta3"` | this README | | 3 | 3.3.0, maintained on the [`3.x`](https://github.com/activeadmin-plugins/active_admin_theme/tree/3.x) branch | `gem "active_admin_theme", "~> 3.3"` (RubyGems) | [v3.3.0 README](https://github.com/activeadmin-plugins/active_admin_theme/blob/v3.3.0/README.md) | ## Screenshots @@ -41,7 +41,7 @@ Pages of the demo app in `test/dummy`. `bundle exec rake screenshots` regenerate Theme 4 is in beta and not on RubyGems yet, so install it from its GitHub tag: ```ruby -gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta2" +gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta3" ``` The gem requires `active_admin` first, so its views and partials win over ActiveAdmin's own. Do not reorder that. diff --git a/docs/migrating-from-v3.md b/docs/migrating-from-v3.md index 870d221..aa7267b 100644 --- a/docs/migrating-from-v3.md +++ b/docs/migrating-from-v3.md @@ -6,7 +6,7 @@ Upgrade ActiveAdmin first, and follow ActiveAdmin's own [upgrade guide](https:// ## Checklist -1. In the `Gemfile`, set `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta2"` (the beta is not on RubyGems) and `activeadmin` to 4.0.0.beta23 or newer. Ruby 3.3 or newer is required. +1. In the `Gemfile`, set `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta3"` (the beta is not on RubyGems) and `activeadmin` to 4.0.0.beta23 or newer. Ruby 3.3 or newer is required. 2. Remove the theme 3 lines from your stylesheet and script manifests: - `@import "wigu/active_admin_theme";` and any `$skin*` variable assignments - `//= require wigu/all` (or the individual `wigu/*` files) diff --git a/lib/active_admin_theme/version.rb b/lib/active_admin_theme/version.rb index e53616b..55de888 100644 --- a/lib/active_admin_theme/version.rb +++ b/lib/active_admin_theme/version.rb @@ -1,3 +1,3 @@ module ActiveAdminTheme - VERSION = "4.0.0.beta2" + VERSION = "4.0.0.beta3" end From f83c3671dee315540d75f8ba58fb1194f4f0cf4f Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Fri, 4 Dec 2026 11:41:00 +0200 Subject: [PATCH 8/9] Review fixes: dropdowns above flashes, row class, nested tables On an index page the flashes shared the title bar's z-index and took its dropdown's clicks. ActiveAdmin clears a row's selected class only from the select-all box. A table in an index cell matched the sticky header selector. Co-Authored-By: Clanker --- .../active_admin_theme/table_crisscross.js | 3 ++ app/tailwind/active_admin_theme.css | 13 ++++--- test/dummy/app/admin/menu_orders.rb | 13 ++++++- test/layout_test.rb | 39 +++++++++++++------ 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/app/javascript/active_admin_theme/table_crisscross.js b/app/javascript/active_admin_theme/table_crisscross.js index 9a17266..f0fc1ed 100644 --- a/app/javascript/active_admin_theme/table_crisscross.js +++ b/app/javascript/active_admin_theme/table_crisscross.js @@ -36,4 +36,7 @@ document.addEventListener("click", (event) => { document.addEventListener("change", (event) => { const toggleAll = event.target.closest(".batch-actions-toggle-all") if (toggleAll) clear(toggleAll.closest("table")) + // ActiveAdmin sets a row's selected class only from the select-all box. + const checkbox = event.target.closest(".batch-actions-resource-selection") + checkbox?.closest("tr")?.classList.toggle("selected", checkbox.checked) }) diff --git a/app/tailwind/active_admin_theme.css b/app/tailwind/active_admin_theme.css index c26c6f6..23d8825 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -182,9 +182,9 @@ * v3. The main column takes the table's width, and the bars around the * content stay at the viewport width. layout.js sets --aat-viewport-width, * which leaves out a classic scrollbar. A sticky bar is a stacking context: - * its z-index keeps the title bar's dropdowns above the page content and its - * sticky header row, and below #site-header. Below 768px the table scrolls in - * its wrapper. */ + * the title bar sits above the flashes, the page content and its sticky + * header row, so its dropdowns take clicks over them, and below #site-header. + * Below 768px the table scrolls in its wrapper. */ @media (width >= 48rem) { :has(> [data-aat-page] .index-as-table) { min-width: fit-content; @@ -195,6 +195,9 @@ z-index: 10; width: var(--aat-viewport-width, 100vw); } + :has(> [data-aat-page] .index-as-table) > #page-header { + z-index: 20; + } [data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(.index-as-table) { grid-template-columns: 270px minmax(min-content, 1fr); } @@ -219,7 +222,7 @@ * would leave behind. Below 768px the table scrolls in its wrapper, which a * sticky header cannot leave. */ @media (width >= 48rem) { - [data-aat-sticky-thead] .index-as-table .data-table:not(.skip-sticky-headers) > thead > tr:first-child > th, + [data-aat-sticky-thead] .index-as-table > .data-table:not(.skip-sticky-headers) > thead > tr:first-child > th, table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table) > thead > tr:first-child > th { position: sticky; top: var(--aa-header-height); @@ -229,7 +232,7 @@ table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table) > thead > tr:first-child > th { background-color: var(--aat-table-header); } - :is([data-aat-sticky-thead] .index-as-table .data-table:not(.skip-sticky-headers), table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table)).with-sticky-rows > thead > tr:first-child > th:first-child { + :is([data-aat-sticky-thead] .index-as-table > .data-table:not(.skip-sticky-headers), table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table)).with-sticky-rows > thead > tr:first-child > th:first-child { z-index: 3; box-shadow: inset -1px 0 0 var(--aat-border), inset 0 -1px 0 var(--aat-border); } diff --git a/test/dummy/app/admin/menu_orders.rb b/test/dummy/app/admin/menu_orders.rb index f02c25b..254f20c 100644 --- a/test/dummy/app/admin/menu_orders.rb +++ b/test/dummy/app/admin/menu_orders.rb @@ -1,11 +1,20 @@ # An index with an action-item dropdown whose items hang over the table -# toolbar, which the batch actions render (test/layout_test.rb). +# toolbar, which the batch actions render, and a table in a cell +# (test/layout_test.rb). ActiveAdmin.register Order, as: "MenuOrder" do menu false config.batch_actions = true filter :status, as: :select, collection: Order::STATUSES + # ?flash=1 shows flash messages under the title bar. + controller do + before_action(only: :index) do + flash.now[:notice] = "Export queued" if params[:flash] + flash.now[:alert] = "Another export is running" if params[:flash] + end + end + action_item :new_export, only: :index do dropdown_menu_tag "New export", id: "new-export" do item "CSV", "/admin/dropdown_menu/echo?to=csv" @@ -20,5 +29,7 @@ id_column column :reference column :status + # A table in a cell keeps its own header: only the index header sticks. + column("Lines") { |order| table_for [order.reference], class: "nested-lines" do column("Line") { |line| line } end } end end diff --git a/test/layout_test.rb b/test/layout_test.rb index 135b1a0..cea0a26 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -168,18 +168,21 @@ def test_wide_table_outside_an_index_keeps_its_own_scroll assert_operator page.evaluate_script("document.documentElement.scrollWidth"), :<=, 1100 end - def test_action_item_dropdown_items_take_clicks_over_the_index_toolbar + def test_action_item_dropdown_items_take_clicks_over_the_index_toolbar_and_flashes page.current_window.resize_to(1280, 800) - visit "/admin/menu_orders" - find("button", text: "New export").click - hits = page.evaluate_script(<<~JS) - [...document.querySelectorAll("#new-export a, [data-test-action-items] a[href*='to=']")].filter((a) => a.offsetParent).map((a) => { - const box = a.getBoundingClientRect() - const hit = document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2) - return a.contains(hit) ? a.textContent.trim() : hit.className - }) - JS - assert_equal %w[CSV XML JSON PDF], hits + ["/admin/menu_orders", "/admin/menu_orders?flash=1"].each do |path| + visit path + find("button", text: "New export").click + hits = page.evaluate_script(<<~JS) + [...document.querySelectorAll("#new-export a, [data-test-action-items] a[href*='to=']")].filter((a) => a.offsetParent).map((a) => { + const box = a.getBoundingClientRect() + const hit = document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2) + return a.contains(hit) ? a.textContent.trim() : hit.className + }) + JS + assert_equal %w[CSV XML JSON PDF], hits, path + end + assert_selector ".aat-flash", count: 2 find("a[href$='to=xml']").click assert_text "xml" end @@ -199,6 +202,10 @@ def test_index_table_header_sticks_under_the_top_bar assert_equal "auto", page.evaluate_script("getComputedStyle(document.getElementById('sticky-table-for').parentElement).overflowX") assert_equal "static", page.evaluate_script("getComputedStyle(document.querySelector('table.wide-demo thead th')).position") + visit "/admin/menu_orders" + assert_equal "sticky", page.evaluate_script("getComputedStyle(document.querySelector('.index-as-table > .data-table > thead th')).position") + assert_equal "static", page.evaluate_script("getComputedStyle(document.querySelector('table.nested-lines thead th')).position") + page.current_window.resize_to(700, 500) visit "/admin/customers" assert_equal "static", page.evaluate_script("getComputedStyle(document.querySelector('.data-table thead th')).position") @@ -284,6 +291,16 @@ def test_crisscross_marks_row_and_column_and_the_row_click_ticks_its_checkbox refute find("table.data-table tbody tr:nth-child(2) input[type=checkbox]").checked? end + def test_a_row_unchecked_after_select_all_loses_the_selected_class + visit "/admin/customers" + find(".batch-actions-toggle-all").click + assert_selector "table.data-table tbody tr.selected", count: 30 + all("table.data-table tbody tr:nth-child(2) td")[3].click + refute find("table.data-table tbody tr:nth-child(2) input[type=checkbox]").checked? + assert_selector "table.data-table tbody tr.selected", count: 29 + assert_no_selector "table.data-table tbody tr:nth-child(2).selected" + end + def test_a_checked_row_is_highlighted visit "/admin/customers" checkbox = find("table.data-table tbody tr:nth-child(2) input[type=checkbox]") From 9561dc55583d75e5c4424cc3a35d1cd91d120a4b Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Fri, 4 Dec 2026 11:42:35 +0200 Subject: [PATCH 9/9] Index title bar: confirm dialogs above their backdrop The sticky title bar's stacking context held an open confirm_dialog under Flowbite's body-level backdrop, so its buttons took no clicks. Since beta2. Co-Authored-By: Clanker --- app/tailwind/active_admin_theme.css | 6 ++++++ test/dummy/app/admin/menu_orders.rb | 7 ++++++- test/layout_test.rb | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/tailwind/active_admin_theme.css b/app/tailwind/active_admin_theme.css index 23d8825..d0f5eb5 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -198,6 +198,12 @@ :has(> [data-aat-page] .index-as-table) > #page-header { z-index: 20; } + /* An open confirm_dialog's backdrop is a child of body at z-index 40, so + * the title bar gives up its stacking context while the dialog is open. */ + :has(> [data-aat-page] .index-as-table) > #page-header:has(.aat-confirm-modal:not(.hidden)) { + position: relative; + z-index: auto; + } [data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(.index-as-table) { grid-template-columns: 270px minmax(min-content, 1fr); } diff --git a/test/dummy/app/admin/menu_orders.rb b/test/dummy/app/admin/menu_orders.rb index 254f20c..4368a77 100644 --- a/test/dummy/app/admin/menu_orders.rb +++ b/test/dummy/app/admin/menu_orders.rb @@ -1,5 +1,5 @@ # An index with an action-item dropdown whose items hang over the table -# toolbar, which the batch actions render, and a table in a cell +# toolbar, which the batch actions render, a confirm dialog, and a table in a cell # (test/layout_test.rb). ActiveAdmin.register Order, as: "MenuOrder" do menu false @@ -24,6 +24,11 @@ end end + action_item :purge, only: :index do + confirm_dialog_tag "Purge exports", id: "purge-exports", title: "Purge exports?", url: "/admin/confirm_dialog/echo", + class: "action-item-button" + end + index do selectable_column id_column diff --git a/test/layout_test.rb b/test/layout_test.rb index cea0a26..3103a13 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -187,6 +187,23 @@ def test_action_item_dropdown_items_take_clicks_over_the_index_toolbar_and_flash assert_text "xml" end + def test_a_confirm_dialog_from_an_index_title_bar_takes_clicks + page.current_window.resize_to(1280, 800) + visit "/admin/menu_orders" + find("button", text: "Purge exports").click + hits = page.evaluate_script(<<~JS) + [...document.querySelectorAll("#purge-exports button")].filter((b) => b.offsetParent).map((b) => { + const box = b.getBoundingClientRect() + const hit = document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2) + return b.contains(hit) ? b.textContent.trim() : String(hit.className) + }) + JS + assert_equal %w[Confirm Cancel], hits + within("#purge-exports") { click_button "Cancel" } + assert_no_selector "#purge-exports", visible: :visible + assert_equal "sticky", page.evaluate_script("getComputedStyle(document.getElementById('page-header')).position") + end + def test_index_table_header_sticks_under_the_top_bar page.current_window.resize_to(1280, 500) visit "/admin/customers"