Skip to content

refactor(admin): use Flarum's own controls for the admin toggles - #72

Open
karl-bullock wants to merge 4 commits into
mainfrom
fix/admin-settings-native-controls
Open

karl-bullock wants to merge 4 commits into
mainfrom
fix/admin-settings-native-controls

Conversation

@karl-bullock

@karl-bullock karl-bullock commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

The admin page and the category editor drew their own checkboxes: a raw <label class="checkbox"> around a native <input type="checkbox">. Stock Flarum does not do that in admin — boolean settings go through buildSettingComponent({ type: 'bool' }), which renders the Switch component and ties the help text to the input, and a list of named options is rendered as Switch rows (see flarum/audit).

This replaces both with core components, so the extension's admin screens look and behave like the rest of Flarum.

Thanks to @huoxin233: #64 first proposed using Flarum's native Switch for the navigation settings. This covers that and the allowed-groups list in the category editor.

Changes

  • js/src/admin/components/SupportAdminPage.tsx: the three navigation settings are rendered with this.buildSettingComponent({ setting, label, help, type: 'bool', default }). Defaults are unchanged (1, 1, 0).
  • js/src/admin/components/CategoryEditorModal.tsx: the allowed-groups list uses Switch rows instead of raw checkboxes. The container is named LinkRobinsSupport-groupSwitches, and the group links to the help text about leaving all switches off.
  • less/admin.less: the hand-written .checkbox rules are gone; the group container only sets the vertical rhythm core's switch lists use.
  • js/dist rebuilt.

Why Switch and not Checkbox for the group list

Core's Checkbox is used icon-only. With a visible label it draws a red cross when off, which reads as "not allowed" — but an unchecked box here means "no restriction", since an empty list allows every group the ticket type permits. Switch rows are what Flarum itself uses for a list of named options (flarum/audit's LimitedSettingsModal).

Before / after

Both navigation captures show all three controls on Flarum Test #2. Before, the section uses raw checkboxes. After, it uses Flarum switches with their help text attached.

Navigation before
Navigation after

Allowed user groups — before: raw checkboxes. After: Switch rows.

Groups before
Groups after

The same list at phone width with six groups (three of them created on the bench for the check):

Groups after, phone

Checks

Run on the linkrobins bench (Flarum 2.0.2, stock image + this checkout):

  • Navigation section renders three Switches; label.checkbox nodes on the page: 0.
  • Each switch's <input> carries aria-describedby pointing at its help text.
  • Toggle a switch → Save Changes enables → Save → "Your changes were saved." → reload keeps the new value.
  • Category editor renders three switch rows, 0 raw checkboxes; ticking groups, saving the category and reopening it keeps the selection.
  • Phone width (390px) with six groups: rows fit, 24px spacing between switches, no horizontal overflow.
  • Light and dark theme (Appearance → Dark Mode): switches readable, no contrast problem.
  • On Flarum Test Some CSS Issues #2, the group has the accessible name “Allowed user groups” and aria-describedby resolves to the help text on desktop and at 390 px.
  • npm run check-typings, npm run format-check, npm run build: clean.

Review screenshots are stored on the pr-assets-72 branch.

The navigation settings and the allowed-groups list were hand-rolled
`<label class="checkbox">` inputs. No core admin page renders those: a
boolean setting goes through buildSettingComponent with type 'bool',
which renders a Switch and ties the help text to the input with
aria-describedby, and a list of named options is rendered as Switch rows
(flarum/audit's limited-settings form).

The three navigation settings now go through buildSettingComponent with
their existing defaults, and the allowed-groups list uses Switch rows.
Core's Checkbox is not used for the list: it is styled for icon-only use,
and with a visible label an unchecked box shows a red cross, which reads
as "forbidden" when an empty list actually means no restriction.

js/dist is rebuilt in the next commit.
Includes transpiled JS/TS, and Typescript declaration files (typings).
@karl-bullock

Copy link
Copy Markdown
Member Author

Verification notes for this branch at 5d1c1d0:

  • Navigation: live bench, all three switches carry aria-describedby pointing at their own help text; the admin page has no label.checkbox nodes left.
  • Allowed groups: the container is role="group" + aria-describedby (the aria-labelledby change is fix(admin): label the allowed groups from the visible heading #76). With every switch off the category saves allowedGroupIds = null, and an ordinary member still gets canCreate = true; with only Admins ticked that same member gets canCreate = false.
  • Bundle: js/dist/admin.js at this commit is byte-identical to a fresh webpack --mode production build of js/src. forum.js and the per-component dist files drift when rebuilt, but they drift on main too — not from this branch.
  • Screenshots: the images live on the pr-assets-72 branch (links in the description), not in the diff. Deleting that branch would break the description.
  • Evidence gap: the description says light and dark were checked; among the five assets there is no dark or RTL capture. The dark pass was run, the picture is missing.
  • Stacking: fix(admin): label the allowed groups from the visible heading #76 is based on this branch. After this merges, check that fix(admin): label the allowed groups from the visible heading #76 still shows only its own commit once it retargets to main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant