You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn/components/naming-your-components.md
+22-18Lines changed: 22 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,8 @@ order: 3
4
4
script: ["tag-name-input.js"]
5
5
---
6
6
7
-
Custom Element tag names must have at least one dash (`-`) in them, and so you probably want to name your element with
8
-
two distinct words like `theme-picker`. You can use as many dashes as you want, you're not limited to one.
7
+
Custom Element _tag names_ must have at least one dash (`-`) in them. As such you probably want to name your element
8
+
with two distinct words like `theme-picker`. You can use as many dashes as you want, you're not limited to one.
9
9
10
10
There are some specific rules that you must adhere to to make a valid tag name:
11
11
@@ -16,7 +16,7 @@ There are some specific rules that you must adhere to to make a valid tag name:
16
16
- It _can_ contain underscores, and numbers.
17
17
- It _can_ contain characters from different alphabets, such as `é`, `ð`, `ö`, `爱`.
18
18
19
-
An invalid name will cause a `DOMException` to be thrown when you set up your custom element.
19
+
An invalid name will result in a `DOMException` when you set up your custom element.
20
20
21
21
Try typing a tag name below to see if it's a valid custom element tag:
22
22
@@ -37,10 +37,9 @@ Try typing a tag name below to see if it's a valid custom element tag:
37
37
</p>
38
38
</label>
39
39
40
-
### Some tag names are reserved
40
+
### Reserved tag names
41
41
42
-
There are also some names which are _disallowed_ because they have existed in the HTML spec prior to the creation of
43
-
custom elements. These are:
42
+
Some names are _disallowed_ because they have existed in the HTML spec before custom elements were added. These are:
44
43
45
44
-`annotation-xml`
46
45
-`color-profile`
@@ -63,13 +62,18 @@ While none of the following is prescriptive, here are some tips and tricks on ho
63
62
64
63
### Avoid splitting compound words
65
64
66
-
It can be tricky to think of two words for every element, so it might be tempting to add a dash inside a compound word,
67
-
for example `tool-tip` or `over-lay`. Adding dashes to compound words like this can look a little confusing so it might
68
-
be beneficial to spend the effort and think of another word to add to these, for example `tooltip-popover` or
69
-
`overlay-dialog`.
65
+
It can be tricky to think of two words for every element, so it might be tempting to add a dash inside a compound word.
66
+
For example splitting "tooltip" into `tool-tip` or "overlay" into `over-lay`. Adding dashes to compound words like this
67
+
can look a little confusing so it might be beneficial to spend the effort and think of another word to add to these,
68
+
for example `tooltip-popover` or `overlay-dialog`.
70
69
71
-
If your Autonomous Custom Element borrows concepts from other built-ins then you could make up a name that uses the
72
-
built-in, for example `fancy-button`, `color-input`, `radial-meter`.
70
+
### Using names from existing elements
71
+
72
+
If your _Autonomous Custom Element_ borrows concepts from other built-ins then you could make up a similar name. For
73
+
example `fancy-button` for an element like `<button>`, `color-input` for an element like `<input>`, or `radial-meter`
74
+
for an element like `<meter>`. You might want to avoid doing this for all except _Customised Built-ins_. If your element
75
+
doesn't share anything in common with an existing built-in, then it's best to avoid having a similar name, as it might
76
+
cause confusion.
73
77
74
78
### Make the name concise, but clear
75
79
@@ -79,12 +83,12 @@ unclear what they do until you familiarise yourself with them. Good components h
79
83
clear!
80
84
81
85
Conversely using difficult to spell words can cause errors and typos more often. It's best to avoid difficult to spell
82
-
element names like `<abbreviated-text>` or `<widget-accessory>`. Some general rules that make words difficult to spell:
83
-
words longer than 10 characters, words with double letters (abbreviated, occasion, accommodate), words using different
84
-
letters with the same sound (necessary, accessory), words with "silent" constanants (knack, assign, doubt). In these
85
-
cases it might be better to replace a hard to spell word with a simpler word, e.g. `<abbreviated-text>` could be come
86
-
`<short-text>`, `<approximate-date>` could be `<rounded-date>`. Alternatively you could replace one hard to spell word
87
-
with two easier to spell words that mean the same thing, for example `<establish-account>` could be `<set-up-account>`.
86
+
element names like `<abbreviated-text>` or `<widget-accessory>`. Words longer than 10 characters tend to be difficult
87
+
to spell, so try to avoid those. Words with double letters (abbreviated, occasion, accommodate) can be tricky too. Words
88
+
using different letters with the same sound (necessary, accessory) often get misspelled. Words with "silent" consanants
89
+
(knack, assign, doubt) are difficult, especially people whom English is not their first language. In these cases it might
90
+
be better to replace a hard to spell word with a simpler word, e.g. `<abbreviated-text>` could be come `<short-text>`, `<approximate-date>` could be `<rounded-date>`. Alternatively you could replace one hard to spell word with two easier to
91
+
spell words that mean the same thing, for example `<establish-account>` could be `<set-up-account>`.
88
92
89
93
Tag names don't have to use a single dash! Names like `<auto-complete-input>` or `<ajax-form-provider>` are valid, and
90
94
can sometimes be clearer! However just like long methods or class names they can be overly verbose which makes them
0 commit comments