Skip to content

Commit

Permalink
Merge pull request #2853 from tvdeyen/growl-component-slot
Browse files Browse the repository at this point in the history
feat(alchemy-growl): Allow innerHTML as message
  • Loading branch information
tvdeyen authored May 1, 2024
2 parents fad5df2 + 424209b commit f123201
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/javascript/alchemy_admin/components/growl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { growl } from "alchemy_admin/growler"

class Growl extends HTMLElement {
connectedCallback() {
growl(this.getAttribute("message"), this.getAttribute("type") || "notice")
growl(this.message, this.getAttribute("type") || "notice")
}

get message() {
return this.getAttribute("message") || this.innerHTML
}
}

Expand Down
24 changes: 24 additions & 0 deletions spec/javascript/alchemy_admin/components/growl.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import "alchemy_admin/components/growl"
import { renderComponent } from "./component.helper"

describe("alchemy-growl", () => {
it("should have the given message from attribute", () => {
const html = `
<div id="flash_notices"></div>
<alchemy-growl message="Foo Bar"></alchemy-growl>
`
renderComponent("alchemy-growl", html)
const message = document.querySelector("alchemy-message")
expect(message.textContent).toMatch("Foo Bar")
})

it("should have the given message from innerHTML", () => {
const html = `
<div id="flash_notices"></div>
<alchemy-growl>Foo Bar</alchemy-growl>
`
renderComponent("alchemy-growl", html)
const message = document.querySelector("alchemy-message")
expect(message.textContent).toMatch("Foo Bar")
})
})

0 comments on commit f123201

Please sign in to comment.