Skip to content

Commit 661cfc0

Browse files
authored
docs: update outdated DropdownField mention and links, add Field story, update labelling techniques (#33699)
1 parent 1661d99 commit 661cfc0

15 files changed

+69
-45
lines changed

packages/react-components/react-combobox/stories/src/Dropdown/DropdownAccessibility.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
### Do
44

5-
- **Provide a label for the Dropdown.** This can be done either by using the `DropdownField` component with a `label` prop, or by using a [custom labeling technique](#TODO).
5+
- **Provide a label for the Dropdown.** This can be done either by using the `Field` component with a `label` prop, or by using a custom labeling technique like a custom `<label for="dropdownId">` element, `aria-label` or `aria-labelledby`.
66
- **Use Dropdown when you need JSX or styled options, otherwise use Select.** For simple single-select use cases, consider using `Select` for better accessibility and mobile support.
77
- **Use multi-select Dropdown when you have 10+ options, otherwise use a Checkbox group.** For simple multiselect use cases with less than 10 options, consider using a group of `Checkbox` components.
88
- **Set `inlinePopup={true}` when possible for better VoiceOver support.** The `inlinePopup` prop will cause the listbox popup to be rendered immediately after the button in the DOM. Safari does not support `aria-owns`, so this enables iOS VoiceOver swipe navigation between the button and options.
9-
- **Review [known accessiblity issues](./?path=/docs/concepts-developer-accessibility-components-dropdown--page).**
9+
- **Review [known accessiblity issues](./?path=/docs/concepts-developer-accessibility-components-dropdown--docs).**
1010

1111
### Don't
1212

1313
- **Don't nest interactive controls in Dropdown slots or children.** The `Dropdown`'s `button` slot and children of `<Option>` components will not expose nested interactive elements to screen reader users, and additional non-`Option` children in the `listbox` slot will not be keyboard accessible.
1414
- **Don’t place the Dropdown button on a surface which doesn’t have a sufficient contrast.** The colors adjacent to the input should have a sufficient contrast. Particularly, the color of input with filled darker and lighter styles needs to provide greater than 3 to 1 contrast ratio against the immediate surrounding color to pass accessibility requirements. When using underline or outline styles, ensure the color of bottom border stroke has a sufficient contrast of greater than 3 to 1 against the immediate surrounding color.
1515

16-
Read the [Dropdown accessibility spec](./?path=/docs/concepts-developer-accessibility-components-dropdown--page) for more detailed information, as well as full descriptions of semantics and keyboard behavior.
16+
Read the [Dropdown accessibility spec](./?path=/docs/concepts-developer-accessibility-components-dropdown--docs) for more detailed information, as well as full descriptions of semantics and keyboard behavior.

packages/react-components/react-combobox/stories/src/Dropdown/DropdownActiveOptionChange.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export const ActiveOptionChange = (props: Partial<DropdownProps>) => {
3535
return (
3636
<div className={styles.root}>
3737
{activeOptionText}
38-
<label id={dropdownId}>Schedule a meeting</label>
39-
<Dropdown aria-labelledby={dropdownId} onActiveOptionChange={onActiveOptionChange} {...props}>
38+
<label htmlFor={dropdownId}>Schedule a meeting</label>
39+
<Dropdown id={dropdownId} onActiveOptionChange={onActiveOptionChange} {...props}>
4040
<Option text="Katri Athokas" onMouseEnter={onMouseEnter}>
4141
<Persona
4242
avatar={{ color: 'colorful', 'aria-hidden': true }}

packages/react-components/react-combobox/stories/src/Dropdown/DropdownAppearance.stories.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export const Appearance = (props: Partial<DropdownProps>) => {
4848
<div className={styles.root}>
4949
<div>
5050
<h3>Outline</h3>
51-
<label id={`${dropdownId}-outline`}>Select an animal</label>
52-
<Dropdown aria-labelledby={`${dropdownId}-outline`} placeholder="-" appearance="outline" {...props}>
51+
<label htmlFor={`${dropdownId}-outline`}>Select an animal</label>
52+
<Dropdown id={`${dropdownId}-outline`} placeholder="-" appearance="outline" {...props}>
5353
<Option>Cat</Option>
5454
<Option>Dog</Option>
5555
<Option>Bird</Option>
@@ -58,8 +58,8 @@ export const Appearance = (props: Partial<DropdownProps>) => {
5858

5959
<div>
6060
<h3>Underline</h3>
61-
<label id={`${dropdownId}-underline`}>Select an animal</label>
62-
<Dropdown aria-labelledby={`${dropdownId}-underline`} placeholder="-" appearance="underline" {...props}>
61+
<label htmlFor={`${dropdownId}-underline`}>Select an animal</label>
62+
<Dropdown id={`${dropdownId}-underline`} placeholder="-" appearance="underline" {...props}>
6363
<Option>Cat</Option>
6464
<Option>Dog</Option>
6565
<Option>Bird</Option>
@@ -68,8 +68,8 @@ export const Appearance = (props: Partial<DropdownProps>) => {
6868

6969
<div className={styles.filledDarker}>
7070
<h3>Filled Darker</h3>
71-
<label id={`${dropdownId}-filledDarker`}>Select an animal</label>
72-
<Dropdown aria-labelledby={`${dropdownId}-filledDarker`} placeholder="-" appearance="filled-darker" {...props}>
71+
<label htmlFor={`${dropdownId}-filledDarker`}>Select an animal</label>
72+
<Dropdown id={`${dropdownId}-filledDarker`} placeholder="-" appearance="filled-darker" {...props}>
7373
<Option>Cat</Option>
7474
<Option>Dog</Option>
7575
<Option>Bird</Option>
@@ -78,13 +78,8 @@ export const Appearance = (props: Partial<DropdownProps>) => {
7878

7979
<div className={styles.filledLighter}>
8080
<h3>Filled Lighter</h3>
81-
<label id={`${dropdownId}-filledLighter`}>Select an animal</label>
82-
<Dropdown
83-
aria-labelledby={`${dropdownId}-filledLighter`}
84-
placeholder="-"
85-
appearance="filled-lighter"
86-
{...props}
87-
>
81+
<label htmlFor={`${dropdownId}-filledLighter`}>Select an animal</label>
82+
<Dropdown id={`${dropdownId}-filledLighter`} placeholder="-" appearance="filled-lighter" {...props}>
8883
<Option>Cat</Option>
8984
<Option>Dog</Option>
9085
<Option>Bird</Option>

packages/react-components/react-combobox/stories/src/Dropdown/DropdownClearable.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export const Clearable = () => {
1717

1818
return (
1919
<div className={styles.root}>
20-
<Label id={dropdownId}>Pick a color</Label>
21-
<Dropdown clearable aria-labelledby={dropdownId} placeholder="Select a color">
20+
<Label htmlFor={dropdownId}>Pick a color</Label>
21+
<Dropdown clearable id={dropdownId} placeholder="Select a color">
2222
<Option>Red</Option>
2323
<Option>Green</Option>
2424
<Option>Blue</Option>

packages/react-components/react-combobox/stories/src/Dropdown/DropdownComplexOptions.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export const ComplexOptions = (props: Partial<DropdownProps>) => {
1818
const styles = useStyles();
1919
return (
2020
<div className={styles.root}>
21-
<label id={dropdownId}>Schedule a meeting</label>
22-
<Dropdown aria-labelledby={dropdownId} {...props}>
21+
<label htmlFor={dropdownId}>Schedule a meeting</label>
22+
<Dropdown id={dropdownId} {...props}>
2323
<Option text="Katri Athokas">
2424
<Persona
2525
avatar={{ color: 'colorful', 'aria-hidden': true }}

packages/react-components/react-combobox/stories/src/Dropdown/DropdownControllingOpenAndClose.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export const ControllingOpenAndClose = () => {
2626
return (
2727
<div className={styles.root}>
2828
<Checkbox value="open" name="state" label="open" checked={open} onChange={onChange} />
29-
<label id={dropdownId}>Best pet</label>
30-
<Dropdown aria-labelledby={dropdownId} placeholder="Select an animal" open={open} onOpenChange={handleOpenChange}>
29+
<label htmlFor={dropdownId}>Best pet</label>
30+
<Dropdown id={dropdownId} placeholder="Select an animal" open={open} onOpenChange={handleOpenChange}>
3131
{options.map(option => (
3232
<Option key={option} disabled={option === 'Ferret'}>
3333
{option}

packages/react-components/react-combobox/stories/src/Dropdown/DropdownCustomOptions.stories.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,8 @@ export const CustomOptions = (props: Partial<DropdownProps>) => {
7676
const styles = useStyles();
7777
return (
7878
<div className={styles.root}>
79-
<label id={dropdownId}>Best pet</label>
80-
<Dropdown
81-
aria-labelledby={dropdownId}
82-
listbox={{ className: styles.listbox }}
83-
placeholder="Select an animal"
84-
{...props}
85-
>
79+
<label htmlFor={dropdownId}>Best pet</label>
80+
<Dropdown id={dropdownId} listbox={{ className: styles.listbox }} placeholder="Select an animal" {...props}>
8681
<CustomOptionGroup label="Land" options={land} />
8782
<CustomOptionGroup label="Sea" options={water} />
8883
</Dropdown>

packages/react-components/react-combobox/stories/src/Dropdown/DropdownDefault.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const Default = (props: Partial<DropdownProps>) => {
1919
const styles = useStyles();
2020
return (
2121
<div className={styles.root}>
22-
<label id={dropdownId}>Best pet</label>
23-
<Dropdown aria-labelledby={dropdownId} placeholder="Select an animal" {...props}>
22+
<label htmlFor={dropdownId}>Best pet</label>
23+
<Dropdown id={dropdownId} placeholder="Select an animal" {...props}>
2424
{options.map(option => (
2525
<Option key={option} disabled={option === 'Ferret'}>
2626
{option}

packages/react-components/react-combobox/stories/src/Dropdown/DropdownDisabled.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const Disabled = (props: Partial<DropdownProps>) => {
1919
const styles = useStyles();
2020
return (
2121
<div className={styles.root}>
22-
<label id={comboId}>Best pet</label>
23-
<Dropdown aria-labelledby={comboId} disabled placeholder="Select an animal" {...props}>
22+
<label htmlFor={comboId}>Best pet</label>
23+
<Dropdown id={comboId} disabled placeholder="Select an animal" {...props}>
2424
{options.map(option => (
2525
<Option key={option}>{option}</Option>
2626
))}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import { Dropdown, Field, makeStyles, Option } from '@fluentui/react-components';
3+
import type { DropdownProps } from '@fluentui/react-components';
4+
5+
const useStyles = makeStyles({
6+
root: {
7+
maxWidth: '400px',
8+
},
9+
});
10+
11+
export const WithField = (props: Partial<DropdownProps>) => {
12+
const styles = useStyles();
13+
const options = ['Cat', 'Caterpillar', 'Corgi', 'Chupacabra', 'Dog', 'Ferret', 'Fish', 'Fox', 'Hamster', 'Snake'];
14+
return (
15+
<Field label="Best pet" required hint="Try picking 'Cat'" className={styles.root}>
16+
<Dropdown placeholder="Select an animal" {...props}>
17+
{options.map(option => (
18+
<Option key={option} disabled={option === 'Ferret'}>
19+
{option}
20+
</Option>
21+
))}
22+
</Dropdown>
23+
</Field>
24+
);
25+
};
26+
27+
WithField.parameters = {
28+
docs: {
29+
description: {
30+
story: 'Field can be used with Dropdown to provide a label, description, error message, and more.',
31+
},
32+
},
33+
};

0 commit comments

Comments
 (0)