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:
parent
dd4048669c
commit
222af635ae
1 changed files with 4 additions and 1 deletions
|
|
@ -115,9 +115,12 @@ defmodule MvWeb.CoreComponents do
|
||||||
else: ["btn", assigns.class]
|
else: ["btn", assigns.class]
|
||||||
|
|
||||||
# Prevent interaction when disabled
|
# Prevent interaction when disabled
|
||||||
|
# Remove navigation attributes to prevent "Open in new tab", "Copy link" etc.
|
||||||
link_attrs =
|
link_attrs =
|
||||||
if assigns[:disabled] do
|
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
|
else
|
||||||
rest
|
rest
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue