5
5
6
6
In the [ previous section] [ defining-a-component ] we learned about _ Autonomous Custom Elements_ vs _ Customized Built-in
7
7
Elements_ . The most popular way to make elements is to use the _ Autonomous Custom Element_ style, by making up your own
8
- tag and extending ` HTMLElement ` . However, each style comes with different trade-offs.
8
+ tag and extending ` HTMLElement ` . Each style comes with different trade-offs.
9
9
10
10
Choosing a type of component to build will depend on a lot of factors. _ Autonomous Custom Elements_ give you a blank
11
11
canvas to work with. _ Customized Built-ins_ ** extend** the element you're customizing. Here are some considerations to
@@ -24,13 +24,13 @@ also means existing code that queries for `button` elements will also find your
24
24
` .querySelectorAll('button') ` will find all button elements, including ones which are _ Customized Built-in elements_ .
25
25
The way to find _ non-Customized Built-ins_ is to use a selector like: ` .querySelectorAll('button:not([is])') ` .
26
26
27
- This difference in tag name also effects how you'll select for these elements in CSS. There are additional CSS
27
+ This difference in tag name also effects how you'll select for these elements in CSS. It also has some additional CSS
28
28
considerations...
29
29
30
30
### CSS & Styling
31
31
32
32
Given _ Autonomous Custom Elements_ have their own tag, they are unlikely to conflict with existing CSS. They can have
33
- _ classes_ added to them, and so can be styled by existing CSS but it is opt-in.
33
+ _ classes_ added to them, and so can be styled by existing CSS but it's opt-in.
34
34
35
35
As _ Customized Built-ins_ keep their tags (e.g. ` <button is="fancy-button"> ` ) any CSS that has rules like ` button {} `
36
36
will apply. This means if you have some existing CSS that applies to _ built-ins_ , it'll also apply to the _ Customized
@@ -41,7 +41,7 @@ All _built-ins_ have some _user-agent CSS_ supplied already, for example `div` e
41
41
styles, so ` <button is="fancy-button"> ` will look the same as ` <button> ` until you customize it further.
42
42
43
43
If you want to customize a _ built-in_ by applying only new styles and not adding any new logic, it might be best to use
44
- a CSS class instead. The main benefit of _ Customized Built-ins_ is to extend or add new logic.
44
+ a CSS class instead. _ Customized Built-ins_ are best used when extending or adding new logic.
45
45
46
46
If you create an _ Autonomous Custom Element_ (e.g. ` <fancy-button> ` ) you'll need to style it from scratch as _ Autonomous
47
47
Custom Elements_ have no default CSS. You will probably want to add some CSS to these elements - even if it's just
@@ -68,7 +68,7 @@ want to customize a _built-in_. Here's a list of _built-ins_ that you can custom
68
68
- ` <section> `
69
69
- ` <span> `
70
70
71
- _ ShadowDOM_ can be really useful for providing encapsulated markup and styles. Styles within _ ShadowDOM_ don't effect
71
+ _ ShadowDOM_ can be really useful for providing encapsulated markup and styles. Styles within _ ShadowDOM_ don't affect
72
72
the rest of the page, and so it can be a really useful place to add styles to your elements. If this is a high priority,
73
73
you might find using an _ Autonomous Custom Element_ to be a better choice than the limited set of built-ins which can
74
74
use _ ShadowDOM_ .
@@ -105,23 +105,23 @@ These all extend from `HTMLElement` themselves so you'll still get everything `H
105
105
106
106
Extending from ` HTMLButtonElement ` , for example, means your class will inherit the button's properties, like ` .type ` ,
107
107
` .disabled ` , ` .forms ` , ` .name ` , ` .value ` , and so on. On one hand this would be a lot of code to replicate yourself with
108
- an _ Autonomous Custom Element_ , but on the other hand your element adopting all of these might not be desirable.
108
+ an _ Autonomous Custom Element_ , but your element adopting all these might not be desirable.
109
109
110
- When extending from a _ Customized Built-in_ , overriding the already existing methods and properties can have undesirable
110
+ When extending from a _ Customized Built-in_ overriding the existing methods and properties can have undesirable
111
111
consequences. It might be tempting to add new ` .type ` values to ` <button> ` for example, but in doing so you might run
112
112
into issues with code that isn't expecting to see the newly added logic.
113
113
114
114
### Accessibility
115
115
116
116
_ Customized Built-ins_ have very good accessibility information built right into them. Most have an _ implicit role_
117
- which means that assistive technologies know how to interpret them. For example using a _ screen reader_ , it is possible
118
- to navigate through all of the headings in a web page, and the purpose of form controls is explained as each one is
119
- focused (e.g. buttons are announced not only by their label but also referred to as "buttons").
120
-
121
- _ Autonomous Custom Elements_ , on the other hand, do not have any accessibility information built into them. Assistive
122
- technologies such as _ screen readers_ will read the contents of the element as if it were plain text; treating it the
123
- same as a ` <div> ` or ` < span>` . It's possible to customize how assistive technology like _ screen readers_ handle your
124
- element by using the [ Accessible Rich Internet Applications (or ARIA)] [ aria ] APIs, such as the ` role= ` attribute.
117
+ which means that assistive technologies know how to interpret them. For example using a _ screen reader_ , it's possible
118
+ to navigate through all the headings in a web page, and the purpose of form controls is explained as each one is focused
119
+ (e.g. buttons are announced not only by their label but also referred to as "buttons").
120
+
121
+ _ Autonomous Custom Elements_ , do not have any accessibility information built into them. Assistive technologies such as
122
+ _ screen readers_ will read the contents of the element as if it were plain text; treating it the same as a ` <div> ` or
123
+ ` < span>` . It's possible to customize how assistive technology like _ screen readers_ handle your element by using the
124
+ [ Accessible Rich Internet Applications (or ARIA)] [ aria ] APIs, such as the ` role= ` attribute.
125
125
126
126
Accessibility can be hard to get right. Many assistive tools behave differently, and much like browsers, support is not
127
127
universal and consistent. It's always worth getting comfortable with these tools, and testing your web applications
0 commit comments