Skip to content
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

Do not override author-set, global attributes #4

Open
stramel opened this issue Feb 12, 2019 · 0 comments
Open

Do not override author-set, global attributes #4

stramel opened this issue Feb 12, 2019 · 0 comments
Assignees
Labels
new lint rule New lint rule request

Comments

@stramel
Copy link
Collaborator

stramel commented Feb 12, 2019

Global attributes are those that are present on all HTML elements. Some examples include tabindex and role. A custom element may wish to set its initial tabindex to 0 so it will be keyboard focusable. But you should always check first to see if the developer using your element has set this to another value. If, for example, they've set tabindex to -1, it's a signal that they don't wish for the element to be interactive.

Ensure that there is a check for the attribute before altering (set/remove) the attribute in the connectedCallback.

if (!this.hasAttribute('foo')) this.setAttribute('foo', 'bar')

Resource:
https://developers.google.com/web/fundamentals/web-components/best-practices#do-not-override-author-set-global-attributes
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes

@stramel stramel added the new lint rule New lint rule request label Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new lint rule New lint rule request
Projects
None yet
Development

No branches or pull requests

2 participants