Comments (6)
I tried <a data={{'calc-key': calcKey}}>
but an error occurs inside dataset module so seems is not doable to implement this use case. Anyway it would be good to document the behavior
This works: <a data={{calcKey: calcKey}}>
from snabbdom-pragma.
While for data- attributes will not work with property with dash, style accepts property with dashs so something like:
return <a style-background-color={'blue'}>
will not work due to the way deepifyKeys
works
from snabbdom-pragma.
deepifyKeys
is parth of the Modules as attributes feature
Allowing you to consume Snabbdom modules from attributes without worrying about using object.
The drawback of this feature is every attribute using dash is considered as a module key, giving you the opportunity to set deep objects.
from snabbdom-pragma.
deepifyKeys is parth of the Modules as attributes feature
I've got that.
My issue is when the property has a dash, something like MODULE-PROPERTY-WITHDASH
I would expect that <div style-background-color={'blue'}>
would set style.background-color
property to 'blue'. The equivalent to h('div', {style: {'background-color': 'blue'}})
but instead it sets h('div', {style: {background: {color: 'blue'}}})
.
IMO is a bug but if not at least should be documented
from snabbdom-pragma.
Snabbdom style module is using the both way to define style.
if (name[0] === '-' && name[1] === '-') {
(elm as any).style.setProperty(name, cur);
} else {
(elm as any).style[name] = cur;
}
As style in JS is mean to be used that way, you should really go using camelCase styles.
<div style-backgroundColor ={'blue'}></div>
But we should consider to do not split more than the first dash.
from snabbdom-pragma.
As style in JS is mean to be used that way, you should really go using camelCase styles
This is an option for style, but in case of class there is no option when the class name has a dash in it. The example bellow will set 'alertPrimary' class instead of 'alert-primary':
<div class-alertPrimary={true}></div>
In fact snabbdom modules handle properties with dash slightly different:
style module:
Accepts both properties with dash or with camel-case
h('div', {style: {'background-color': 'blue'}})
h('div', {style: {'backgroundColor': 'blue'}})
The examples below will produce the same effect
class module
Requires to use the property with dash because the camelCase one will match a different class
h('div', {class: {alertPrimary: true}}) // sets alertPrimary class
h('div', {class: {'alert-primary': true}}) // sets alert-primary class
dataset/data module:
An error occurs when using properties with dash (a restriction of HTMLElement.dataset
)
h('div', {dataset: {itemKey: 1}}) //fine
h('div', {dataset: {'item-key': 1}}) // throws
In my option only the first dash should be split. Also, should be documented that dataset/data module does not accepts properties with dash
from snabbdom-pragma.
Related Issues (20)
- Add Typescript transpiler HOT 1
- Performance improvements HOT 18
- Typescript strict mode supported? HOT 16
- 'animate', 'animateTransform' are SVG elements HOT 3
- Typescript rewrite
- VNodes in children become undefined after createElement() HOT 12
- Add ES6 module build HOT 8
- Having trouble with all attributes besides Class and ID HOT 3
- Unable to run test scripts HOT 2
- Destructuration is broken for custom components HOT 10
- 'No default export' error with TypeScript HOT 1
- Certain SVG attributes aren't parsed
- Destructuring "type parallelism" error in createElement
- Compilation failures with TypeScript 3.2 HOT 1
- Span with value zero can break application
- Hi. Does snabbdom-pragma work with esbuild?
- not rendering properly data and aria attributes HOT 3
- Is `h('div#id.class1.class2', ...)` needed ? HOT 2
- Consider to return a vnode object instead of calling h() HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snabbdom-pragma.