Allow for booleans and numbers to be passed via data attributes
See original GitHub issueWhat
Ensure that config passed by data attributes is typed sensibly for the way we want to use it.
Why
Attributes passed via data attributes will always be strings, but in some cases we want to be able to treat them as booleans or numbers.
For example:
data-prevent-double-click
on buttons which is a booleandata-maxlength
on the character count which is a number
Who needs to work on this
Developers
Who needs to review this
Developers
Done when
- Attributes that we expect to be booleans or numbers are typed as such when used as config in a component
- We have good test coverage of any function(s) required to implement this
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Using boolean-value of attributes in JSX - Stack Overflow
You can just omit the value assignment; the attribute will be assigned a value of true by default. Instead of doing any of:...
Read more >Boolean attributes - HTML 5
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 >How You Can Use HTML5 Custom Data Attributes and Why
Gajendar Singh walks you through HTML5 custom data attributes, why they're useful, ... Let's say a given class name begins with numbers.
Read more >How to Use HTML Data Attributes - DEV Community
Adding a data attribute is easy. Any HTML element can have any number of data attributes added to its opening tag. We simply...
Read more >Using data attributes - Learn web development | MDN
To get a data attribute through the dataset object, get the property by the part of the attribute name after data- (note that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We touched on it briefly in https://github.com/alphagov/govuk-frontend/issues/2736#issuecomment-1208303510 but I think the biggest downsides were:
dump
filter but we weren’t confident that port maintainers would have this available in every templating languageAs flagged in the linked issue, Bootstrap now support this via
data-bs-config
but that’s in addition to the individual data attributes.For options/config did the https://github.com/alphagov/govuk-frontend/issues/2736 JSON approach get ruled out?
Input: JSON string from data attribute
Output: JavaScript object with types