Skip to content

Commit f8dc139

Browse files
committed
second pass on naming components
1 parent 3645795 commit f8dc139

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

learn/components/naming-your-components.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ order: 3
44
script: ["tag-name-input.js"]
55
---
66

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.
99

1010
There are some specific rules that you must adhere to to make a valid tag name:
1111

@@ -16,7 +16,7 @@ There are some specific rules that you must adhere to to make a valid tag name:
1616
- It _can_ contain underscores, and numbers.
1717
- It _can_ contain characters from different alphabets, such as `é`, `ð`, `ö`, ``.
1818

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.
2020

2121
Try typing a tag name below to see if it's a valid custom element tag:
2222

@@ -37,10 +37,9 @@ Try typing a tag name below to see if it's a valid custom element tag:
3737
</p>
3838
</label>
3939

40-
### Some tag names are reserved
40+
### Reserved tag names
4141

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:
4443

4544
- `annotation-xml`
4645
- `color-profile`
@@ -63,13 +62,18 @@ While none of the following is prescriptive, here are some tips and tricks on ho
6362

6463
### Avoid splitting compound words
6564

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`.
7069

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.
7377

7478
### Make the name concise, but clear
7579

@@ -79,12 +83,12 @@ unclear what they do until you familiarise yourself with them. Good components h
7983
clear!
8084

8185
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>`.
8892

8993
Tag names don't have to use a single dash! Names like `<auto-complete-input>` or `<ajax-form-provider>` are valid, and
9094
can sometimes be clearer! However just like long methods or class names they can be overly verbose which makes them

0 commit comments

Comments
 (0)