Skip to content

Commit 812e824

Browse files
docs(combobox): remove use of placeholder (#3219)
Removes use of placeholder in combobox and adds guidelines to explain why it should not be used. Updates docs page to use documentation template. Also makes adjustments to combobox template so that value and menu args can be passed. CSS-41
1 parent a97d8aa commit 812e824

File tree

4 files changed

+141
-263
lines changed

4 files changed

+141
-263
lines changed

components/combobox/stories/combobox.mdx

Lines changed: 0 additions & 101 deletions
This file was deleted.

components/combobox/stories/combobox.stories.js

Lines changed: 79 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,36 @@ import { disableDefaultModes } from "@spectrum-css/preview/modes";
33
import { isDisabled, isFocused, isInvalid, isKeyboardFocused, isLoading, isOpen, isQuiet, size } from "@spectrum-css/preview/types";
44
import pkgJson from "../package.json";
55
import { ComboBoxGroup } from "./combobox.test.js";
6-
import { Template } from "./template.js";
6+
import { VariantGroup } from "./template.js";
77

88
/**
99
* Comboboxes combine a text entry with a picker menu, allowing users to filter longer lists to only the selections matching a query.
10+
*
11+
* ## Usage notes
12+
*
13+
* ### General notes
14+
*
15+
* - Combobox uses `.spectrum-PickerButton` instead of a `.spectrum-Picker`
16+
* - The following classes must be added:
17+
* - `.spectrum-Combobox-textfield` is required on the Textfield outer element (`.spectrum-Textfield`)
18+
* - `.spectrum-Combobox-input` is required on the `<input>` element inside of Textfields (`.spectrum-Textfield-input`)
19+
* - `.spectrum-Combobox-button` is required on the FieldButton (`.spectrum-ActionButton spectrum-ActionButton--sizeM`)
20+
*
21+
* ### Indicating validity and focus
22+
*
23+
* Validity and focus must be bubbled up to the parent so descendants siblings can be styled. Implementations should add the following classes to the `.spectrum-Combobox` parent class in the following situations:
24+
*
25+
* - `.is-focused` - when the input or button is focused with the mouse
26+
* - `.is-keyboardFocused` - when the input or button is focused with the keyboard
27+
* - `.is-valid` - when the input has an explicit valid state
28+
* - `.is-invalid` - when the input has an explicit invalid state
29+
* - `.is-disabled` - when the control is disabled; should also add to the `.spectrum-Combobox-textfield` and include a `[disabled]` attribute to the `.spectrum-Combobox-button`
30+
* - `.is-loading` - when the progress circle is being shown
31+
*
32+
* ### Don't use placeholder text
33+
* 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.
34+
*
35+
* Instead of placeholder text, use the [help text](/docs/components-help-text--docs) 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.
1036
*/
1137
export default {
1238
title: "Combobox",
@@ -50,6 +76,16 @@ export default {
5076
control: "select",
5177
if: { arg: "showFieldLabel", truthy: true },
5278
},
79+
value: {
80+
name: "Value",
81+
description: "The value shows the option that a user has selected.",
82+
type: { name: "string" },
83+
table: {
84+
type: { summary: "string" },
85+
category: "Content",
86+
},
87+
control: { type: "text" },
88+
},
5389
content: { table: { disable: true } },
5490
},
5591
args: {
@@ -64,151 +100,66 @@ export default {
64100
isDisabled: false,
65101
showFieldLabel: false,
66102
testId: "combobox",
103+
content: [
104+
(passthroughs, context) => Menu({
105+
role: "listbox",
106+
subrole: "option",
107+
selectionMode: "single",
108+
hasDividers: true,
109+
items: [
110+
{
111+
label: "Ballard",
112+
isSelected: true,
113+
isChecked: true,
114+
},
115+
{
116+
label: "Fremont",
117+
},
118+
{
119+
label: "Greenwood",
120+
},
121+
{
122+
type: "divider",
123+
},
124+
{
125+
label: "United States of America",
126+
isDisabled: true,
127+
},
128+
],
129+
...passthroughs,
130+
}, context),
131+
],
67132
},
68133
parameters: {
69134
packageJson: pkgJson,
70135
},
71136
};
72137

73138
export const Default = ComboBoxGroup.bind({});
139+
Default.tags = ["!autodocs"];
74140
Default.args = {
75141
isOpen: true,
76142
fieldLabelText: "Select location",
77-
content: [
78-
Menu({
79-
role: "listbox",
80-
subrole: "option",
81-
isSelectable: true,
82-
items: [
83-
{
84-
label: "Ballard",
85-
isSelected: true,
86-
isChecked: true,
87-
},
88-
{
89-
label: "Fremont",
90-
},
91-
{
92-
label: "Greenwood",
93-
},
94-
{
95-
type: "divider",
96-
},
97-
{
98-
label: "United States of America",
99-
isDisabled: true,
100-
},
101-
],
102-
}),
103-
],
143+
value: "Ballard",
104144
};
105145

106146
// ********* DOCS ONLY ********* //
107-
export const WithLabel = Template.bind({});
108-
WithLabel.tags = ["!dev"];
109-
WithLabel.args = {
110-
showFieldLabel: true,
111-
fieldLabelText: "Country",
112-
isOpen: true,
113-
};
114-
WithLabel.parameters = {
115-
chromatic: { disableSnapshot: true },
116-
};
117-
118-
export const Closed = Template.bind({});
119-
Closed.tags = ["!dev"];
120-
Closed.args = {
121-
isOpen: false,
122-
};
123-
Closed.parameters = {
124-
chromatic: { disableSnapshot: true },
125-
};
126-
127-
export const Invalid = Template.bind({});
128-
Invalid.tags = ["!dev"];
129-
Invalid.args = {
130-
isInvalid: true,
131-
};
132-
Invalid.parameters = {
133-
chromatic: { disableSnapshot: true },
134-
};
135-
136-
export const Loading = Template.bind({});
137-
Loading.tags = ["!dev"];
138-
Loading.args = {
139-
isLoading: true,
140-
};
141-
Loading.parameters = {
142-
chromatic: { disableSnapshot: true },
143-
};
144-
145-
export const Disabled = Template.bind({});
146-
Disabled.tags = ["!dev"];
147-
Disabled.args = {
148-
isDisabled: true,
149-
};
150-
Disabled.parameters = {
151-
chromatic: { disableSnapshot: true },
152-
};
153-
154-
// Quiet
155-
export const Quiet = Template.bind({});
156-
Quiet.tags = ["!dev"];
157-
Quiet.args = {
158-
isQuiet: true,
159-
};
160-
Quiet.parameters = {
161-
chromatic: { disableSnapshot: true },
162-
};
163-
164-
export const QuietWithLabel = Template.bind({});
165-
QuietWithLabel.tags = ["!dev"];
166-
QuietWithLabel.args = {
167-
showFieldLabel: true,
168-
fieldLabelText: "Country",
169-
isQuiet: true,
170-
};
171-
QuietWithLabel.parameters = {
172-
chromatic: { disableSnapshot: true },
173-
};
174-
175-
export const QuietClosed = Template.bind({});
176-
QuietClosed.tags = ["!dev"];
177-
QuietClosed.args = {
178-
isQuiet: true,
179-
isOpen: false,
180-
};
181-
QuietClosed.parameters = {
182-
chromatic: { disableSnapshot: true },
183-
};
184-
185-
export const QuietInvalid = Template.bind({});
186-
QuietInvalid.tags = ["!dev"];
187-
QuietInvalid.args = {
188-
isQuiet: true,
189-
isInvalid: true,
190-
};
191-
QuietInvalid.parameters = {
192-
chromatic: { disableSnapshot: true },
193-
};
194-
195-
export const QuietLoading = Template.bind({});
196-
QuietLoading.tags = ["!dev"];
197-
QuietLoading.args = {
198-
isQuiet: true,
199-
isLoading: true,
200-
};
201-
QuietLoading.parameters = {
147+
export const DefaultGroup = VariantGroup.bind({});
148+
DefaultGroup.storyName = "Default";
149+
DefaultGroup.args = Default.args;
150+
DefaultGroup.tags = ["!dev"];
151+
DefaultGroup.parameters = {
202152
chromatic: { disableSnapshot: true },
203153
};
204154

205-
export const QuietDisabled = Template.bind({});
206-
QuietDisabled.tags = ["!dev"];
207-
QuietDisabled.args = {
155+
export const QuietGroup = VariantGroup.bind({});
156+
QuietGroup.storyName = "Quiet";
157+
QuietGroup.args = {
158+
...Default.args,
208159
isQuiet: true,
209-
isDisabled: true,
210160
};
211-
QuietDisabled.parameters = {
161+
QuietGroup.tags = ["!dev"];
162+
QuietGroup.parameters = {
212163
chromatic: { disableSnapshot: true },
213164
};
214165

components/combobox/stories/combobox.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ export const ComboBoxGroup = Variants({
3838
isOpen: false,
3939
fieldLabelPosition: "left",
4040
},
41+
{
42+
testHeading: "Truncation",
43+
isOpen: false,
44+
value: "United States of America and to the republic",
45+
},
46+
{
47+
testHeading: "Quiet + truncation",
48+
isOpen: false,
49+
isQuiet: true,
50+
value: "United States of America and to the republic",
51+
}
4152
],
4253
stateData: [
4354
{

0 commit comments

Comments
 (0)