Skip to content

Commit

Permalink
remove attrs even if they don't start with data-
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed Jan 23, 2024
1 parent 2d573f7 commit eb4cc7c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/js/phoenix_live_view/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ let DOM = {
for(let i = targetAttrs.length - 1; i >= 0; i--){
let name = targetAttrs[i].name
if(isIgnored){
if(name.startsWith("data-") && !source.hasAttribute(name) && ![PHX_REF, PHX_REF_SRC].includes(name)){ target.removeAttribute(name) }
if(!source.hasAttribute(name) && ![PHX_REF, PHX_REF_SRC].includes(name)){ target.removeAttribute(name) }
} else {
if(!source.hasAttribute(name)){ target.removeAttribute(name) }
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ defmodule Phoenix.LiveViewTest.E2E.Router do
pipe_through(:browser)

live "/3026", Phoenix.LiveViewTest.E2E.Issue3026Live
live "/3044", Phoenix.LiveViewTest.E2E.Issue3044Live
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/tests/issues/3044.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { test, expect } = require("@playwright/test");
const { syncLV } = require("../../utils");

test("attributes on phx-update='ignore' can be toggled", async ({ page }) => {
await page.goto("/issues/3044");
await syncLV(page);

await expect(page.locator("input")).not.toHaveAttribute("disabled");
await page.locator("button").click();
await syncLV(page);

await expect(page.locator("input")).toHaveAttribute("disabled");
await page.locator("button").click();
await syncLV(page);

await expect(page.locator("input")).not.toHaveAttribute("disabled");
});
26 changes: 26 additions & 0 deletions test/support/e2e/issues/issue_3044.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule Phoenix.LiveViewTest.E2E.Issue3044Live do
use Phoenix.LiveView

@impl Phoenix.LiveView
def mount(_, _, socket) do
{:ok, assign(socket, :disabled, false)}
end

@impl Phoenix.LiveView
def handle_event("toggle", _, socket) do
{:noreply, update(socket, :disabled, &(not &1))}
end

@impl Phoenix.LiveView
def render(assigns) do
~H"""
<input
value={if @disabled, do: "disabled", else: "not disabled"}
disabled={@disabled}
phx-update="ignore"
id="test-input"
/>
<button phx-click="toggle">Toggle</button>
"""
end
end

0 comments on commit eb4cc7c

Please sign in to comment.