fix: make disabled links more robust in CoreComponents.button

Remove navigation attributes (href, navigate, patch) when disabled=true
to prevent 'Open in new tab' and 'Copy link' from working on disabled links.
This makes the disabled state semantically stronger and independent of CSS themes.
This commit is contained in:
Moritz 2025-12-16 14:48:18 +01:00
parent dd4048669c
commit 222af635ae

View file

@ -115,9 +115,12 @@ defmodule MvWeb.CoreComponents do
else: ["btn", assigns.class]
# Prevent interaction when disabled
# Remove navigation attributes to prevent "Open in new tab", "Copy link" etc.
link_attrs =
if assigns[:disabled] do
Map.merge(rest, %{tabindex: "-1", "aria-disabled": "true"})
rest
|> Map.drop([:href, :navigate, :patch])
|> Map.merge(%{tabindex: "-1", "aria-disabled": "true"})
else
rest
end