@spectrum-web-components/textfield 1.4.0-beta.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +119 -71
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## Description
1
+ ## Overview
2
2
 
3
3
  `sp-textfield` components are text boxes that allow users to input custom text entries with a keyboard. Various decorations can be displayed around the field to communicate the entry requirements.
4
4
 
@@ -20,11 +20,83 @@ import '@spectrum-web-components/textfield/sp-textfield.js';
20
20
 
21
21
  When looking to leverage the `Textfield` base class as a type and/or for extension purposes, do so via:
22
22
 
23
- ```
23
+ ```js
24
24
  import { Textfield } from '@spectrum-web-components/textfield';
25
25
  ```
26
26
 
27
- ## Sizes
27
+ ### Anatomy
28
+
29
+ ```html
30
+ <sp-textfield id="basic" label="Name"></sp-textfield>
31
+ ```
32
+
33
+ #### Label
34
+
35
+ A text field must have a label in order to be accessible. A label can be provided either via the `label` attribute, like the previous example or with an `<sp-field-label>` element.
36
+
37
+ ```html
38
+ <sp-field-label for="with-field-label">Name</sp-field-label>
39
+ <sp-textfield id="with-field-label"></sp-textfield>
40
+ ```
41
+
42
+ #### Placeholder
43
+
44
+ Use the `placeholder` attribute to include placeholder text. **Note**: Placeholder text should not be used as a replacement for a label or help help text.
45
+
46
+ ```html
47
+ <sp-field-label for="has-placeholder">Name</sp-field-label>
48
+ <sp-textfield id="has-placeholder" placeholder="ex., John Doe"></sp-textfield>
49
+ ```
50
+
51
+ #### Help text
52
+
53
+ Help text can be accessibly associated with an `<sp-textfield>` element by using the `help-text` or `negative-help-text` slots. When using the `negative-help-text` slot, `<sp-textfield>` will self manage the presence of this content based on the value of the `invalid` property on your `<sp-textfield>` element. Content within the `help-text` slot will be show by default. When your `<sp-textfield>` should receive help text based on state outside of the complexity of `invalid` or not, manage the content addressed to the `help-text` from above to ensure that it displays the right messaging and possesses the right `variant`.
54
+
55
+ See [help text](../help-text) for more information.
56
+
57
+ <sp-tabs selected="self" auto label="Help text usage in textfields">
58
+ <sp-tab value="self">Self managed</sp-tab>
59
+ <sp-tab-panel value="self">
60
+
61
+ ```html
62
+ <sp-field-label for="self">Stay "Positive"</sp-field-label>
63
+ <sp-textfield id="self" pattern="[P][o][s][i][t][i][v][e]" value="Positive">
64
+ <sp-help-text slot="help-text">
65
+ Tell us how you are feeling today.
66
+ </sp-help-text>
67
+ <sp-help-text slot="negative-help-text">Please be "Positive".</sp-help-text>
68
+ </sp-textfield>
69
+ ```
70
+
71
+ </sp-tab-panel>
72
+ <sp-tab value="above">Managed from above</sp-tab>
73
+ <sp-tab-panel value="above">
74
+
75
+ ```html
76
+ <sp-field-label for="managed">Stay "Positive"</sp-field-label>
77
+ <sp-textfield
78
+ id="managed"
79
+ pattern="[P][o][s][i][t][i][v][e]"
80
+ value="Positive"
81
+ oninput='
82
+ const helpText = this.querySelector(`[slot="help-text"]`);
83
+ helpText.textContent = this.invalid ? `Please be "Positive".` : `Tell us how you are feeling today.`;
84
+ helpText.variant = this.invalid ? `negative` : `neutral`;
85
+ '
86
+ >
87
+ <sp-help-text slot="neutral-text">
88
+ Tell us how you're feeling today.
89
+ </sp-help-text>
90
+ <sp-help-text slot="help-text">Please be "Positive".</sp-help-text>
91
+ </sp-textfield>
92
+ ```
93
+
94
+ </sp-tab-panel>
95
+ </sp-tabs>
96
+
97
+ ### Options
98
+
99
+ #### Sizes
28
100
 
29
101
  <sp-tabs selected="m" auto label="Size Attribute Options">
30
102
  <sp-tab value="s">Small</sp-tab>
@@ -77,41 +149,7 @@ import { Textfield } from '@spectrum-web-components/textfield';
77
149
  </sp-tab-panel>
78
150
  </sp-tabs>
79
151
 
80
- ## Variants
81
-
82
- ### Valid
83
-
84
- Dictate the validity state of the text entry with the `valid` attribute.
85
-
86
- ```html
87
- <sp-field-label for="name-1" required>Name</sp-field-label>
88
- <sp-textfield
89
- id="name-1"
90
- placeholder="Enter your name"
91
- valid
92
- value="My Name"
93
- ></sp-textfield>
94
- ```
95
-
96
- ### Invalid
97
-
98
- Dictate the invalidity state of the text entry with the `invalid` attribute.
99
-
100
- ```html
101
- <sp-field-label for="name-2" required>Name</sp-field-label>
102
- <sp-textfield id="name-2" invalid placeholder="Enter your name"></sp-textfield>
103
- ```
104
-
105
- ### Quiet
106
-
107
- The quiet style works best when a clear layout (vertical stack, table, grid) assists in a user's ability to parse the element. Too many quiet components in a small space can be hard to read.
108
-
109
- ```html
110
- <sp-field-label for="name-3">Name (quietly)</sp-field-label>
111
- <sp-textfield id="name-3" placeholder="Enter your name" quiet></sp-textfield>
112
- ```
113
-
114
- ### Types
152
+ #### Types
115
153
 
116
154
  When inputting URLs, telephone numbers, email addresses, or passwords, specify a `type` to provide
117
155
  user affordances like mobile keyboards and obscured characters:
@@ -135,46 +173,56 @@ user affordances like mobile keyboards and obscured characters:
135
173
 
136
174
  If the `type` attribute is not specified, or if it does not match any of these values, the default type adopted is "text."
137
175
 
138
- ## Help text
139
-
140
- Help text can be accessibly associated with an `<sp-textfield>` element by using the `help-text` or `negative-help-text` slots. When using the `negative-help-text` slot, `<sp-textfield>` will self manage the presence of this content based on the value of the `invalid` property on your `<sp-textfield>` element. Content within the `help-text` slot will be show by default. When your `<sp-textfield>` should receive help text based on state outside of the complexity of `invalid` or not, manage the content addressed to the `help-text` from above to ensure that it displays the right messaging and possesses the right `variant`.
176
+ #### Quiet
141
177
 
142
- <sp-tabs selected="self" auto label="Help text usage in textfields">
143
- <sp-tab value="self">Self managed</sp-tab>
144
- <sp-tab-panel value="self">
178
+ The quiet style works best when a clear layout (vertical stack, table, grid) assists in a user's ability to parse the element. Too many quiet components in a small space can be hard to read.
145
179
 
146
180
  ```html
147
- <sp-field-label for="self">Stay "Positive"</sp-field-label>
148
- <sp-textfield id="self" pattern="[P][o][s][i][t][i][v][e]" value="Positive">
149
- <sp-help-text slot="help-text">
150
- Tell us how you are feeling today.
151
- </sp-help-text>
152
- <sp-help-text slot="negative-help-text">Please be "Positive".</sp-help-text>
153
- </sp-textfield>
181
+ <sp-field-label for="name-3">Name (quietly)</sp-field-label>
182
+ <sp-textfield id="name-3" placeholder="Enter your name" quiet></sp-textfield>
154
183
  ```
155
184
 
156
- </sp-tab-panel>
157
- <sp-tab value="above">Managed from above</sp-tab>
158
- <sp-tab-panel value="above">
185
+ ### States
186
+
187
+ Use the `required` attribute to indicate a textfield value is required. Dictate the validity or invalidity state of the text entry with the `valid` or `invalid` attributes.
159
188
 
160
189
  ```html
161
- <sp-field-label for="managed">Stay "Positive"</sp-field-label>
190
+ <sp-field-label for="name-1" required>Name</sp-field-label>
162
191
  <sp-textfield
163
- id="managed"
164
- pattern="[P][o][s][i][t][i][v][e]"
165
- value="Positive"
166
- oninput='
167
- const helpText = this.querySelector(`[slot="help-text"]`);
168
- helpText.textContent = this.invalid ? `Please be "Positive".` : `Tell us how you are feeling today.`;
169
- helpText.variant = this.invalid ? `negative` : `neutral`;
170
- '
171
- >
172
- <sp-help-text slot="neutral-text">
173
- Tell us how you're feeling today.
174
- </sp-help-text>
175
- <sp-help-text slot="help-text">Please be "Positive".</sp-help-text>
176
- </sp-textfield>
192
+ id="name-1"
193
+ placeholder="Enter your name"
194
+ valid
195
+ value="My Name"
196
+ ></sp-textfield>
197
+ <br />
198
+ <sp-field-label for="name-2" required>Name</sp-field-label>
199
+ <sp-textfield id="name-2" invalid placeholder="Enter your name"></sp-textfield>
177
200
  ```
178
201
 
179
- </sp-tab-panel>
180
- </sp-tabs>
202
+ ### Accessibility
203
+
204
+ #### Include a label
205
+
206
+ Every text field should have a label. A field without a label is ambiguous and not accessible.
207
+
208
+ #### Include help text
209
+
210
+ The description in the help text is flexible and encompasses a range of guidance. Sometimes this guidance is about what to input, and sometime it’s about how to input. This includes information such as:
211
+
212
+ - An overall description of the input field
213
+ - Hints for what kind of information needs to be input
214
+ - Specific formatting examples or requirements
215
+
216
+ Learn more about [using help text](https://spectrum.adobe.com/page/text-field/#Use-help-text-to-show-hints,-formatting,-and-requirements).
217
+
218
+ #### Include negative help text
219
+
220
+ Write error messaging in a human-centered way by guiding a user and showing them a solution — don’t simply state what’s wrong and then leave them guessing as to how to resolve it. Ambiguous error messages can be frustrating and even shame-inducing for users. Also, keep in mind that something that a system may deem an error may not actually be perceived as an error to a user.
221
+
222
+ Learn more about [writing error messages](https://spectrum.adobe.com/page/text-field/#Write-error-text-that-shows-a-solution).
223
+
224
+ #### Do not us a placeholder as a replacement for a label or help-text
225
+
226
+ Putting instructions for how to complete an input, requirements, or any other essential information into placeholder text is not accessible. Once a value is entered, placeholder text is no longer viewable; if someone is using an automatic form filler, they will never get the information in the placeholder text.
227
+
228
+ Instead, use the help text description to convey requirements or to show any formatting examples that would help user comprehension. If there's placeholder text and help text at the same time, it becomes redundant and distracting, especially if they're communicating the same thing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/textfield",
3
- "version": "1.4.0-beta.0",
3
+ "version": "1.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -58,12 +58,12 @@
58
58
  "lit-html"
59
59
  ],
60
60
  "dependencies": {
61
- "@spectrum-web-components/base": "1.4.0-beta.0",
62
- "@spectrum-web-components/help-text": "1.4.0-beta.0",
63
- "@spectrum-web-components/icon": "1.4.0-beta.0",
64
- "@spectrum-web-components/icons-ui": "1.4.0-beta.0",
65
- "@spectrum-web-components/icons-workflow": "1.4.0-beta.0",
66
- "@spectrum-web-components/shared": "1.4.0-beta.0"
61
+ "@spectrum-web-components/base": "1.4.0",
62
+ "@spectrum-web-components/help-text": "1.4.0",
63
+ "@spectrum-web-components/icon": "1.4.0",
64
+ "@spectrum-web-components/icons-ui": "1.4.0",
65
+ "@spectrum-web-components/icons-workflow": "1.4.0",
66
+ "@spectrum-web-components/shared": "1.4.0"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@spectrum-css/textfield": "8.0.0-s2-foundations.17"