-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix(ui): camelCase to kebab-case (#970) #1013
Conversation
425be00
to
782d6b3
Compare
@@ -0,0 +1,25 @@ | |||
import type { PropertyDeclaration } from 'lit-element'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool stuff :)
782d6b3
to
f4a5283
Compare
7f0a1a0
to
df30916
Compare
df30916
to
7b4a8bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the other comments we could think about adding an import restriction rule to our ui-library/.eslintrc.js
to prevent ourselves from accidentally using the standard LitElement.
// .eslintrc.js
module.exports = {
...
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['lit'],
importNamePattern: 'LitElement',
message: `Don't use the default LitElement class. Import from /utils/boiler-lit-element instead`,
},
],
},
],
},
...
}
7b4a8bc
to
500a964
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a neat solution for the problem of the attributes.
Found three things over all.
- leftover
has-Error
instead ofhasError
- the used regEx for creating kebab-case is a bit flawed, posted an alternative solution
- Somewhere in the documentation it should be noted that only the
LitElementCustom
should be used
0858bee
to
5679303
Compare
"Somewhere in the documentation it should be noted that only the LitElementCustom should be used" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we do about properties like these?
@property() arialabel!: string; |
They aren't camelCased even though they probably should be. But this might also produce unwanted behaviour with screen readers when kebab-cased. I presume we usually only use them to forward the values to elements further down the tree? We should probably investigate how screen readers behave when aria
attributes are duplicated on the custom element and within the shadow dom of said element.
This might lead to screen readers reading the label or whatever twice.
For the comment of @faselbaum I'd suggest to cover this in a new ticket. From my understanding should the current implementation not break anything, only if attributes like the |
a few things here.
i would ignore it for now, we will definitely stumble on this one during the accessibility epic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The js-example-app
needs to be updated to reflect the changes as well since we're not using the genericBlrComponentRenderer
function there.
True, some of them are broken currently. |
5679303
to
d43afa4
Compare
Objective
Ensure that all property names of our custom elements are reflected as kebab-case HTML attributes in the DOM.
Solution: Simple inheritance & LitElement overrides
We created a base class
BoilerLitElement
that extendsLitElement
and overrides the staticcreateProperty()
method. This customcreateProperty()
method automatically converts the name of any class members marked with the@property
decorator to a kebab-cased attribute in HTML. All our custom elements now extendLitElementCustom
instead ofLitElement
.This solution is simple, light-weight & works well with TypeScript's class inference features.
Dropped approaches
We investigated other solutions to approach this issue but decided to drop them due to complexity or TypeScript incompatibility.
Class mixin approach (dropped)
Class mixins as proposed in Lit's documentation don't play well with TypeScript currently. They work partially and with workarounds but would introduce a lot of complexity to make them adaptable and future proof for our project. It might still be worth it to investigate the mixin pattern in the future but it is out of scope for this issue.
References:
This is as far as we got during research
This solution works on almost all fronts: proper type inference and autocompletion for statics and non-statics in mixin class implementation as well as classes extending the mixin.
It needs more polish to make it easier to adapt for other future mixins. Eg. offer a utility function that creates mixin classes and does the proper type conversion through inference (if possible). It also has the caveat of having to create explicitly named intermediate classes as commented in the code above.
Setting the attribute option in the
@property()
decoratorWe discussed going the route of explicitly naming our attributes through the
@property({ attribute: 'some-attribute-name' })
syntax but decided against it since the current solution is succinct and easy to undo should we decide against it in the future.closes #970