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 diff --git a/README.md b/README.md index 5e57f2f..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. @@ -496,6 +496,35 @@ 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: + +```ruby +index do |table| + table.add_class "skip-sticky-headers" + # 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. + +### 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: @@ -752,6 +781,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/app/javascript/active_admin_theme/table_crisscross.js b/app/javascript/active_admin_theme/table_crisscross.js index 337b747..f0fc1ed 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 @@ -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 504c39c..d0f5eb5 100644 --- a/app/tailwind/active_admin_theme.css +++ b/app/tailwind/active_admin_theme.css @@ -173,14 +173,18 @@ .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 * 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: + * 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; @@ -188,8 +192,18 @@ :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); } + :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); } @@ -206,6 +220,30 @@ .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, 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: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: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 { + 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..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?) %> -