Skip to content

Attribute helper utility #50

@colepeters

Description

@colepeters

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions