Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix class names #118

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ export class Tonic extends window.HTMLElement {

const out = []
for (let i = 0; i < strings.length - 1; i++) {
if (strings[i].endsWith('class=')) {
out.push(strings[i], `"${refs(values[i])}"`)
}
out.push(strings[i], refs(values[i]))
}
out.push(strings[strings.length - 1])
Expand Down
23 changes: 23 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ test('sanity', async t => {
t.ok(parseInt(parts[0]) >= 10)
})

test('multiple class names', t => {
t.plan(1)

class TextTest extends Tonic {
render () {
const className = 'hello world'
return this.html`<button id="text" class=${className}>
hello
</button>`
}
}

Tonic.add(TextTest)

document.body.innerHTML = `
<text-test>hello</text-test>
`

const el = document.getElementById('text')
t.deepEqual(Array.from(el.classList), ['hello', 'world'],
'should have the right content')
})

test('pass an async function as an event handler', t => {
t.plan(1)

Expand Down