mirror of
https://github.com/we-promise/sure.git
synced 2026-05-27 22:44:55 +00:00
* fix(design-system): DS::Button a11y audit Closes #1738. Four concrete fixes surfaced by the savings-goals audit + #1737 universal checklist: 1. Focus ring (WCAG 2.4.7). `base.css` had `focus-visible:outline-gray-900` which is **1.07:1** against the primary button's gray-900 background — invisible. Widen to `outline-2 outline-offset-2`, place outline outside the button via offset, and add a dark-mode `outline-white` so the ring is always visible against the page chrome regardless of the button surface. 2. Touch target (WCAG 2.5.5). Icon-only buttons at the default `:md` size were `w-9 h-9` = 36×36, below the 44×44 enhanced target. Bump `md.icon_container_classes` to `w-11 h-11` and `lg.icon_container_classes` to `w-12 h-12` to keep the size scale intact. `sm` stays at 32×32 (already passes WCAG 2.5.8 AA's 24×24 minimum; intentional compact-density variant). 3. Default button type. `content_tag(:button, ...)` inherits the HTML default `type="submit"`, so a DS::Button rendered inside a form steals Enter-key submission from the first text input (reproducible in the form stepper). Default to `type="button"` in the non-`href` branch; existing form submitters pass `type: "submit"` explicitly and continue to work. The `button_to` (href) branch keeps the submit default because button_to wraps its own form. 4. Icon-only accessible name. Icon-only buttons render no text node, so AT users hear "button" with no name. Derive a humanized aria-label from the icon key (e.g. `icon: "more-horizontal"` → `aria-label="More horizontal"`); explicit `aria: { label: }` on the caller still wins. Soft fallback — callers should still pass meaningful labels for richer copy. Plus: replace the stale `fg-white` icon class on the destructive variant with `text-inverse` (the `fg-*` namespace was deprecated in #1626 so `fg-white` resolved to nothing; the icon was using its helper-default color rather than the white the design intended). Out of scope: - Menu avatar trigger (custom 36×36 button bypassing DS::Button) — belongs to #1743 DS::Menu audit. - DS::FilledIcon `lg` size container (decorative, not interactive) — belongs to #1742. * fix(design-system): force type=submit on StyledFormBuilder#submit The DS::Button default-type-button change in the previous commit broke every `form.submit "Log in"` callsite because `StyledFormBuilder#submit` (app/helpers/styled_form_builder.rb) renders a DS::Button under the hood with no explicit `type:`. After the default flip, those submit buttons rendered as `type="button"`, so submitting forms (login, password reset, every form using `form.submit`) silently no-ops. CI surfaced this via ~30 system tests failing in the `sign_in` helper, which couldn't get past the login page. Pin `type: "submit"` on the DS::Button rendered by `StyledFormBuilder#submit`. The 22 view-level `f.submit` / `render DS::Button.new(type: :submit, ...)` callers already pass type explicitly and are unaffected. * fix(review): href-branch type-button bug + focus-ring tokens + profile Save submit CodeRabbit P1+P2 review on #1840: 1. button.rb: `merged_opts.delete(:href)` always returned nil because Buttonish#initialize strips :href from opts into @href, so the `if href.blank?` guard was ALWAYS true. Every DS::Button rendered via button_to (the href branch) got `type="button"` on the inner button, breaking submission of those button_to-generated forms (e.g. imports/_ready.html.erb publish button, imports/_failure.html.erb try-again button). Drop the local `href = merged_opts.delete(:href)` so the guard now reads the @href reader, leaving the href branch's HTML default intact. 2. settings/profiles/show.html.erb: the Save button is rendered with `render DS::Button.new(...)` inside `styled_form_with` (not via form.submit), so the StyledFormBuilder#submit type-pin from624e9794doesn't cover it. Pass `type: :submit` explicitly so the profile form submits again under the default-type-button policy. 3. base.css: replace raw `outline-gray-900` / `outline-white` with the established alpha-ring focus pattern (focus-visible:ring-alpha-black-300 + theme-dark:ring-alpha-white-300) already used by app/components/settings/provider_card.html.erb and sure-design-system/components.css. Keeps a11y focus ring while using DS tokens. * fix(review): add type: :submit to DS::Button submitters inside forms CI test_system on #1840 surfaced 6 failures (confirm-dialog close, property create/edit, transaction filter apply) caused by the same gap thatdb563f3dstarted addressing: the default-type-button policy on DS::Button means every \`render DS::Button.new(...)\` inside a \`<form>\` (or \`styled_form_with\`) that relies on the HTML default to submit is now an inert \`type="button"\`. Audited every \`render DS::Button.new(\` callsite repo-wide for the combination (no \`type:\`, no \`href:\`, inside a form context) and pinned \`type: :submit\` explicitly on the 12 forms that need it: - layouts/shared/_confirm_dialog.html.erb: Confirm button inside the global \`<form method=\"dialog\">\` — fixes test_should_allow_revoking_API_key_with_confirmation. - properties/{new,edit,balances}.html.erb: Save/Next submitter inside \`styled_form_with\` — fixes test_can_create_property_account, test_can_persist_property_subtype. - transactions/searches/_menu.html.erb: Apply inside the filter form — fixes test_can_filter_uncategorized_transactions, test_all_filters_work_and_empty_state_shows_if_no_match, test_can_open_filters_and_apply_one_or_more. - transactions/bulk_updates/new.html.erb: Save in bulk-edit drawer. - account_sharings/show.html.erb: Save in account-sharing form. - category/deletions/new.html.erb, tag/deletions/new.html.erb: destructive + safe submit buttons in deletion dialog forms. - family_merchants/merge.html.erb: Submit in merge form. - subscriptions/upgrade.html.erb: contribute_and_support_sure submit. - rules/_category_rule_cta.html.erb: Dismiss inside the rule_prompts_disabled form. Cancel/close DS::Button instances inside these same forms intentionally keep the \`type=button\` default since they drive JS-only actions (\`DS--dialog#close\`, \`DS--menu#close\`). * fix(review): add type: :submit to 4 remaining form-context DS::Button callers Second sweep for the same default-type-button regression that24c517ebfixed for 12 callsites. The latest CI run on this branch narrowed the failures from 6 to 2 (the property wizard's Address step still failed because that view was not in the first sweep). Audited via a wider 4000-char form-context window: - app/views/properties/address.html.erb: Save inside styled_form_with — fixes the remaining test_can_create_property_account + test_can_persist_property_subtype by letting Step 3 of the property wizard complete. - app/views/onboardings/goals.html.erb: Submit inside form_with so the onboarding goals step submits. - app/views/account_sharings/show.html.erb (owner-side form): Save button for the family-share permissions form (the non-owner Save was already fixed in24c517eb). - app/views/transactions/_attachments.html.erb: Upload inside styled_form_with — kept the JS-driven hook (attachment_upload_target) but explicit type:submit covers the no-JS fallback. * fix(review): pin type=submit on the Save currencies button Codex P1 (third pass) caught one more in-form DS::Button I missed in the earlier sweeps: \`app/views/settings/preferences/show.html.erb:185\` renders the Save currencies submit deep inside a long \`styled_form_with\` block. The form-context scan I used had a finite look-back window which missed it because the matching \`styled_form_with\` opener sits ~80 lines / 4k+ characters above the button. Switched to a whole-file scan to confirm no further callsite remains.
235 lines
12 KiB
Plaintext
235 lines
12 KiB
Plaintext
<%= content_for :page_title, t(".page_title") %>
|
|
<%= settings_section title: t(".general_title"), subtitle: t(".general_subtitle") do %>
|
|
<div>
|
|
<%= styled_form_with model: @user, class: "space-y-4", data: { controller: "auto-submit-form" } do |form| %>
|
|
<%= form.hidden_field :redirect_to, value: "preferences" %>
|
|
<%= form.select :locale,
|
|
language_options,
|
|
{ label: t(".language"), include_blank: t(".language_auto") },
|
|
{ data: { auto_submit_form_target: "auto" } } %>
|
|
<%= form.fields_for :family do |family_form| %>
|
|
<%= family_form.select :timezone,
|
|
timezone_options,
|
|
{ label: t(".timezone") },
|
|
{ data: { auto_submit_form_target: "auto" } } %>
|
|
<%= family_form.select :date_format,
|
|
Family::DATE_FORMATS,
|
|
{ label: t(".date_format") },
|
|
{ data: { auto_submit_form_target: "auto" } } %>
|
|
<%= form.select :default_account_order,
|
|
AccountOrder.all.map { |order| [ order.label, order.key ] },
|
|
{ label: t(".default_account_order") },
|
|
{ data: { auto_submit_form_target: "auto" } } %>
|
|
<%= family_form.select :country,
|
|
country_options,
|
|
{ label: t(".country") },
|
|
{ data: { auto_submit_form_target: "auto" } } %>
|
|
<%= family_form.select :month_start_day,
|
|
(1..28).map { |day| [localized_ordinal(day), day] },
|
|
{ label: t(".month_start_day"), hint: t(".month_start_day_hint") },
|
|
{ data: { auto_submit_form_target: "auto" } } %>
|
|
<% if @user.family.uses_custom_month_start? %>
|
|
<div class="text-sm text-warning bg-warning/10 p-3 rounded-lg">
|
|
<%= t(".month_start_day_warning") %>
|
|
</div>
|
|
<% end %>
|
|
<p class="text-xs italic pl-2 text-secondary"><%= t(".translations_notice") %></p>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|
|
<% if Current.user.admin? %>
|
|
<%= settings_section title: t(".currencies_title", moniker: family_moniker), subtitle: t(".currencies_subtitle", moniker: family_moniker_downcase) do %>
|
|
<% selected_count_translations = t(".selected_currencies_count") %>
|
|
<div class="space-y-4"
|
|
data-controller="currency-preferences"
|
|
data-currency-preferences-base-currency-value="<%= @user.family.primary_currency_code %>"
|
|
data-currency-preferences-locale-value="<%= I18n.locale %>"
|
|
data-currency-preferences-selected-count-translations-value="<%= selected_count_translations.to_json %>">
|
|
<% additional_preview_currencies = @user.family.secondary_enabled_currency_objects.first(6) %>
|
|
<% additional_currency_count = @user.family.secondary_enabled_currency_objects.count %>
|
|
<div class="rounded-xl border border-secondary p-4 bg-container-inset">
|
|
<div class="grid gap-4 md:grid-cols-2">
|
|
<div>
|
|
<p class="text-xs font-medium uppercase tracking-wide text-secondary"><%= t(".base_currency_label") %></p>
|
|
<div class="mt-2">
|
|
<p class="text-sm font-medium text-primary"><%= @user.family.primary_currency_code %></p>
|
|
<p class="text-sm text-secondary"><%= currency_label(@user.family.primary_currency_code) %></p>
|
|
</div>
|
|
</div>
|
|
<div class="md:border-l md:border-secondary md:pl-4">
|
|
<p class="text-xs font-medium uppercase tracking-wide text-secondary"><%= t(".additional_currencies_label") %></p>
|
|
<% if additional_preview_currencies.any? %>
|
|
<div class="mt-2 flex flex-wrap gap-2">
|
|
<% additional_preview_currencies.each do |currency| %>
|
|
<span class="inline-flex items-center rounded-full bg-surface-inset px-2.5 py-1 text-xs font-medium text-primary">
|
|
<%= currency.iso_code %>
|
|
</span>
|
|
<% end %>
|
|
<% if additional_currency_count > additional_preview_currencies.count %>
|
|
<span class="inline-flex items-center rounded-full bg-surface-inset px-2.5 py-1 text-xs font-medium text-secondary">
|
|
<%= t(".currencies_more", count: additional_currency_count - additional_preview_currencies.count) %>
|
|
</span>
|
|
<% end %>
|
|
</div>
|
|
<% else %>
|
|
<p class="mt-2 text-sm text-secondary"><%= t(".no_additional_currencies") %></p>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex justify-end">
|
|
<%= render DS::Button.new(
|
|
text: t(".manage_currencies"),
|
|
type: :button,
|
|
class: "md:w-auto w-full justify-center",
|
|
data: { action: "currency-preferences#open" }
|
|
) %>
|
|
</div>
|
|
<%= render DS::Dialog.new(
|
|
id: "currency-preferences-dialog",
|
|
auto_open: false,
|
|
disable_frame: true,
|
|
width: "md",
|
|
data: { currency_preferences_target: "dialog" }
|
|
) do |dialog| %>
|
|
<% dialog.with_header(title: t(".manage_currencies"), subtitle: t(".manage_currencies_subtitle")) %>
|
|
<% dialog.with_body do %>
|
|
<% primary_currency_code = @user.family.primary_currency_code %>
|
|
<% selected_currency_codes = @user.family.enabled_currency_codes %>
|
|
<% base_currency_rows, other_currency_rows = Money::Currency.as_options.partition { |currency| currency.iso_code == primary_currency_code } %>
|
|
<% currency_rows = base_currency_rows + other_currency_rows %>
|
|
<%= styled_form_with model: @user, url: user_path(@user), class: "space-y-4", data: { action: "turbo:submit-end->currency-preferences#handleSubmitEnd" } do |form| %>
|
|
<%= form.hidden_field :redirect_to, value: "preferences" %>
|
|
<%= hidden_field_tag "user[family_attributes][id]", @user.family.id %>
|
|
<%= hidden_field_tag "user[family_attributes][enabled_currencies][]", primary_currency_code, id: nil %>
|
|
<div class="flex flex-wrap items-center justify-between gap-3">
|
|
<div class="flex flex-wrap gap-2">
|
|
<%= render DS::Button.new(
|
|
text: t(".select_all_currencies"),
|
|
type: :button,
|
|
variant: :ghost,
|
|
size: :sm,
|
|
data: { action: "currency-preferences#selectAll" }
|
|
) %>
|
|
<%= render DS::Button.new(
|
|
text: t(".select_base_only"),
|
|
type: :button,
|
|
variant: :ghost,
|
|
size: :sm,
|
|
data: { action: "currency-preferences#selectBaseOnly" }
|
|
) %>
|
|
</div>
|
|
<p class="text-sm font-medium text-secondary"
|
|
data-currency-preferences-target="selectedCount"
|
|
role="status"
|
|
aria-live="polite"
|
|
aria-atomic="true"></p>
|
|
</div>
|
|
<div data-controller="list-filter" class="space-y-3">
|
|
<div class="relative">
|
|
<input type="search"
|
|
autocomplete="off"
|
|
placeholder="<%= t(".currency_search_placeholder") %>"
|
|
aria-label="<%= t(".currency_search_placeholder") %>"
|
|
data-list-filter-target="input"
|
|
data-action="input->list-filter#filter"
|
|
class="block w-full border border-secondary rounded-md py-2.5 pl-10 pr-3 bg-container focus:ring-gray-500 sm:text-sm">
|
|
<div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
|
|
<%= icon("search", class: "text-secondary") %>
|
|
</div>
|
|
</div>
|
|
<div data-list-filter-target="list" class="max-h-80 overflow-auto rounded-xl border border-secondary divide-y divide-alpha-black-100 theme-dark:divide-alpha-white-100">
|
|
<p class="hidden px-4 py-3 text-sm text-secondary" data-list-filter-target="emptyMessage">
|
|
<%= t(".no_matching_currencies") %>
|
|
</p>
|
|
<% currency_rows.each do |currency| %>
|
|
<% checked = selected_currency_codes.include?(currency.iso_code) %>
|
|
<% base_currency = currency.iso_code == primary_currency_code %>
|
|
<label class="<%= class_names(
|
|
"filterable-item flex items-start gap-3 px-4 py-3 cursor-pointer transition-colors hover:bg-surface-inset",
|
|
"bg-surface-inset": base_currency,
|
|
"cursor-default": base_currency
|
|
) %>"
|
|
data-filter-name="<%= "#{currency.iso_code} #{currency.name}" %>">
|
|
<%= check_box_tag "user[family_attributes][enabled_currencies][]",
|
|
currency.iso_code,
|
|
checked,
|
|
disabled: base_currency,
|
|
class: "checkbox checkbox--light mt-0.5",
|
|
data: {
|
|
currency_preferences_target: "checkbox",
|
|
action: "change->currency-preferences#updateSelectedCount"
|
|
} %>
|
|
<div class="min-w-0 flex-1">
|
|
<div class="flex items-start justify-between gap-3">
|
|
<div class="min-w-0">
|
|
<div class="flex items-center gap-2">
|
|
<span class="text-sm font-medium text-primary"><%= currency.iso_code %></span>
|
|
<% if base_currency %>
|
|
<span class="inline-flex items-center rounded-full bg-surface px-2 py-0.5 text-[11px] font-medium text-secondary">
|
|
<%= t(".base_currency_badge") %>
|
|
</span>
|
|
<% end %>
|
|
</div>
|
|
<p class="mt-0.5 text-sm text-secondary"><%= currency.name %></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</label>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
<div class="flex justify-end gap-2">
|
|
<%= render DS::Button.new(text: t("shared.cancel"), type: :button, variant: :ghost, data: { action: "DS--dialog#close" }) %>
|
|
<%= render DS::Button.new(text: t(".save_currencies"), type: :submit) %>
|
|
</div>
|
|
<% end %>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|
|
<%= settings_section title: t(".sharing_title", moniker: family_moniker), subtitle: t(".sharing_subtitle", moniker: family_moniker_downcase) do %>
|
|
<div>
|
|
<%= styled_form_with model: @user, class: "space-y-4", data: { controller: "auto-submit-form" } do |form| %>
|
|
<%= form.hidden_field :redirect_to, value: "preferences" %>
|
|
<%= form.fields_for :family do |family_form| %>
|
|
<%= family_form.select :default_account_sharing,
|
|
[
|
|
[t(".sharing_shared"), "shared"],
|
|
[t(".sharing_private"), "private"]
|
|
],
|
|
{ label: t(".sharing_default_label") },
|
|
{ data: { auto_submit_form_target: "auto" } } %>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|
|
<% end %>
|
|
|
|
<%# Preview features toggle — visible to all users, not just admins. Lives at
|
|
the bottom of Preferences as a standalone card (no section header) so the
|
|
toggle row is the entire surface. Posts directly to
|
|
settings#preferences#update via the Settings::PreferencesController,
|
|
matching the auto-submit pattern used on the Appearance page. %>
|
|
<section class="bg-container shadow-border-xs rounded-xl p-4">
|
|
<%= form_with url: settings_preferences_path, method: :patch,
|
|
data: { controller: "auto-submit-form" } do |f| %>
|
|
<%# Wrapping the row in <label for=…> makes the title + description
|
|
themselves a click target for the toggle, so the cursor-pointer
|
|
affordance on the container is honest. %>
|
|
<label for="user_preview_features_enabled" class="flex cursor-pointer items-center gap-4 justify-between">
|
|
<div class="text-sm space-y-1">
|
|
<h4 class="text-primary"><%= t(".preview.title") %></h4>
|
|
<p class="text-secondary"><%= t(".preview.description") %></p>
|
|
</div>
|
|
<%= render DS::Toggle.new(
|
|
id: "user_preview_features_enabled",
|
|
name: "user[preview_features_enabled]",
|
|
checked: @user.preview_features_enabled?,
|
|
data: { auto_submit_form_target: "auto" }
|
|
) %>
|
|
</label>
|
|
<% end %>
|
|
</section>
|