question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML5 boolean attribute on a component

See original GitHub issue

I need to add an HTML5 boolean attribute to a component. Here’s the Handlebars syntax.

{{#my-component data-test-my-component}}
{{/my-component}}

However, in Emblem.js this doesn’t seem possible. Here’s a few variations I’ve tried:

= my-component data-test-my-component [
  some-other-attr='']

= my-component [
  data-test-my-component
  some-other-attr='' ]

Does Emblem.js support this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kketchcommented, Nov 30, 2017

Hey @divmgl the only way to have that “data-” boolean attribute on the root element of your component is to use attributeBindings. And this is not related to emblem, the same is true with handlebars.

As explained in issue #120 the div attribute-name=true syntax allows you to render boolean html attributes.

But in the example you gave initially, data-test-my-component is expected to be the value for a positional parameter, see: https://guides.emberjs.com/v2.16.0/components/passing-properties-to-a-component/#toc_positional-params

So it won’t be bound to a html attribute, Ember will rather look for a data-test-my-component property on your rendering context (component, controller) and pass the value of that property as the value for positional parameter, which isn’t what you want.

And regarding emblem and positional params the only way to use them is to use the regular inline syntax for attributes (no brackets).

0reactions
thec0kemancommented, Dec 14, 2017

Emblem does support position params inside blocks:

= foo-bar [
  'hi!'
  baz=1
]

=> example => test

Read more comments on GitHub >

github_iconTop Results From Across the Web

The 24 Boolean Attributes of HTML - Jens Oliver Meiert
The presence of a boolean attribute on an element represents the “true” value, and the absence of the attribute represents the “false” value...
Read more >
What does it mean in HTML 5 when an attribute is a boolean ...
A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence...
Read more >
Boolean attributes - HTML 5
A number of attributes in HTML5 are boolean attributes . The presence of a boolean attribute on an element represents the true value,...
Read more >
How to use boolean attributes in Web Components
The HTML Spec is a little more strict on boolean attributes on built-in elements - it states that the attribute must be set...
Read more >
Boolean attributes - HTML Spec
A number of attributes are boolean attributes . The presence of a boolean attribute on an element represents the true value, and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found