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

Attribute helper utility #50

Open
colepeters opened this issue Jun 30, 2023 · 0 comments
Open

Attribute helper utility #50

colepeters opened this issue Jun 30, 2023 · 0 comments

Comments

@colepeters
Copy link
Member

colepeters commented Jun 30, 2023

Conditional attributes can be tough to work with.

Our current recommended practice is using Object.keys:

export default function MyElement ({ html, state }) {
  const { attrs } = state
  const disabled = Object.keys(attrs).includes('disabled')
    ? 'disabled'
    : ''

  return html`<button ${disabled}>I Can Haz?</button>`
}

We should look into a helper to make this less cumbersome.

To keep in mind: there are attributes (e.g. many ARIA attributes) which are non-boolean.

See an example use case discussed in our Discord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant