Commit fb71cd1
authored
Fix ID generation to ensure it produces valid CSS identifiers (#3139)
* Move the logic of generating the ID into its own utility
function.
* Ensure the utility function generates IDs that are valid
CSS identifiers.
`shortid.generate()` by itself will generates IDs that
are not always valid¹ CSS identifiers (e.g. will start
with a digit). So, when other parts of the codebase will
use those IDs as a selector, a `SyntaxError`² will be thrown
(i.e. `'#...' is not a valid selector`).
The `slds-` prefix is used so to keep things simple.
`shortid.characters()` requires "a string of all 64 unique
characters"³, which means that in order to generate valid
CSS identifiers a-z, A-Z, and some "ISO 10646 characters
U+00A0 and higher"¹ will need to be included.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
¹ From https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
" In CSS, identifiers (including element names, classes, and IDs
in selectors) can contain only the characters [a-zA-Z0-9] and
ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and
the underscore (_); they cannot start with a digit, two hyphens,
or a hyphen followed by a digit. "
² https://dom.spec.whatwg.org/#selectors
³ https://github.com/dylang/shortid/blob/937ce2c8dd7001baec1785cb8dce6e6fe1bcf61f/README.md#shortidcharactersstring1 parent b2ab369 commit fb71cd1
File tree
51 files changed
+157
-234
lines changed- components
- accordion
- app-launcher
- badge
- brand-band
- button-group
- card/__docs__
- carousel
- checkbox
- color-picker
- combobox
- data-table
- date-picker
- docked-composer
- expandable-section
- expression
- files
- filter
- input
- location-map
- modal
- panel/filtering
- pill-container
- popover
- progress-bar
- progress-indicator
- radio-group
- radio
- setup-assistant
- slider
- split-view
- tabs
- textarea
- tooltip
- tree/private
- visual-picker
- welcome-mat
- docs
- utilities
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
51 files changed
+157
-234
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | 13 | | |
19 | 14 | | |
20 | 15 | | |
| 16 | + | |
| 17 | + | |
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
26 | 23 | | |
27 | | - | |
| 24 | + | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 14 | | |
20 | 15 | | |
21 | 16 | | |
| |||
27 | 22 | | |
28 | 23 | | |
29 | 24 | | |
| 25 | + | |
| 26 | + | |
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
| |||
35 | 32 | | |
36 | 33 | | |
37 | 34 | | |
38 | | - | |
| 35 | + | |
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | 13 | | |
| 14 | + | |
19 | 15 | | |
20 | 16 | | |
21 | 17 | | |
| |||
66 | 62 | | |
67 | 63 | | |
68 | 64 | | |
69 | | - | |
| 65 | + | |
70 | 66 | | |
71 | 67 | | |
72 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| 23 | + | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | 12 | | |
18 | 13 | | |
| 14 | + | |
| 15 | + | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
| |||
151 | 148 | | |
152 | 149 | | |
153 | 150 | | |
154 | | - | |
| 151 | + | |
155 | 152 | | |
156 | 153 | | |
157 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 14 | | |
20 | 15 | | |
21 | 16 | | |
| |||
28 | 23 | | |
29 | 24 | | |
30 | 25 | | |
| 26 | + | |
31 | 27 | | |
32 | 28 | | |
33 | 29 | | |
| |||
211 | 207 | | |
212 | 208 | | |
213 | 209 | | |
214 | | - | |
| 210 | + | |
215 | 211 | | |
216 | 212 | | |
217 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
| |||
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
| 38 | + | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
446 | 445 | | |
447 | 446 | | |
448 | 447 | | |
449 | | - | |
450 | | - | |
| 448 | + | |
| 449 | + | |
451 | 450 | | |
452 | 451 | | |
453 | 452 | | |
| |||
0 commit comments