Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
074ae28
Add accessibility scenarios for the Accordion, Button and Popover com…
adamsamec Nov 9, 2021
3352e77
Change scenario titles
adamsamec Nov 10, 2021
5e45bbd
Use string directly as component prop value
adamsamec Nov 11, 2021
cd895a1
Merge remote-tracking branch 'origin' into accessibility-scenarios
adamsamec Nov 11, 2021
f126e6d
Merge branch 'accessibility-scenarios' of https://github.com/adamsame…
adamsamec Nov 11, 2021
0e82680
replace alert with status text and fix warnings
adamsamec Nov 11, 2021
f9c34fc
Replace useCallback with ordinary function
adamsamec Nov 11, 2021
930148b
Revert the title for the scenarios list page
adamsamec Nov 11, 2021
49691d4
Removed unnecessary fragment
adamsamec Nov 11, 2021
8bdd2c0
Use <Label> components
adamsamec Nov 11, 2021
cfe3331
Remove not used exports
adamsamec Nov 15, 2021
7cf5b9c
Merge master
adamsamec Nov 19, 2021
f4ea222
Change files
Nov 22, 2021
562db7c
Replace Calendar buttons scenario with Messenger buttons scenario, ad…
adamsamec Nov 25, 2021
d1a35ad
Merge branch 'accessibility-scenarios' of https://github.com/adamsame…
adamsamec Nov 25, 2021
c0676e7
Add ToggleButton component scenario and replace button element with B…
adamsamec Nov 25, 2021
adca036
Merge branch 'master' into accessibility-scenarios
adamsamec Nov 30, 2021
b8f0d1d
Merge branch 'master' into accessibility-scenarios
adamsamec Dec 1, 2021
8ad4bca
Replace calendar scenario link with messenger scenario link and gramm…
adamsamec Dec 2, 2021
2ef8dd4
Add Link component scenario, and small changes in Accordion
adamsamec Dec 2, 2021
5858cc2
Add beta version of SplitButton scenario
adamsamec Dec 2, 2021
1192d34
Make SplitButton scenario working
adamsamec Dec 4, 2021
a4861c3
Change label for menu button within SplitButton
adamsamec Dec 4, 2021
9ef8fdc
Replace Button with MenuButton in Menu scenario
adamsamec Dec 8, 2021
39a2008
Merge branch 'master' into accessibility-scenarios
adamsamec Dec 8, 2021
98b93cb
Fix error in Menu scenario
adamsamec Dec 8, 2021
19f3ecd
Merge branch 'master' into accessibility-scenarios
adamsamec Dec 16, 2021
d7e8650
Refactor aria-label for menu button within split button
adamsamec Dec 16, 2021
97dba3f
Extract Postpone menu item into separate button
adamsamec Dec 16, 2021
6e4f0b6
Add tooltip button without triggerAriaAttribute prop
adamsamec Dec 16, 2021
b9495c7
Merge branch 'master' into accessibility-scenarios
adamsamec Dec 21, 2021
71d6349
Add other gender radio option
adamsamec Dec 21, 2021
b2cee2c
Rename disabled links and add nav region
adamsamec Dec 21, 2021
bff21cf
Add heading and description for toggle buttons
adamsamec Dec 21, 2021
d7a5eea
Add FAQ accordion scenario and change radios in personal form accordi…
adamsamec Dec 22, 2021
d731e75
Add h1 for accordion scenarios
adamsamec Dec 22, 2021
cbcf7bd
Fix lint errors and change Tooltip scenario for more real life examples
adamsamec Dec 22, 2021
54aef09
Add icon buttons for Tooltip scenario
adamsamec Dec 23, 2021
1cf3536
Merge branch 'master' into accessibility-scenarios
adamsamec Jan 13, 2022
9d95202
Add x of Y and Submit button to simple form accordion scenario
adamsamec Jan 13, 2022
0ac2a8f
Add menu with split item scenario
adamsamec Jan 13, 2022
c68c2f5
Change menu items in menu with split item scenario
adamsamec Jan 13, 2022
15b1fed
Merge branch 'master' into accessibility-scenarios
adamsamec Jan 18, 2022
c41c0ba
Fix visible label in split button in menu secondary action
adamsamec Jan 18, 2022
4e10fe2
Remove X of Y in Accordion scenario
adamsamec Jan 18, 2022
589d404
Enable dismiss of tooltip with Escape
adamsamec Jan 18, 2022
b552a69
Move password hint button between password label and input field
adamsamec Jan 19, 2022
9a78db1
Reintroduce X of Y for personal form accordion scenario
adamsamec Jan 21, 2022
2750d26
Add as='h2' for accordion headers
adamsamec Feb 3, 2022
fd65b42
Remove X of Y in personal form accordion scenario
adamsamec Feb 3, 2022
2a10532
Merge branch 'master' into accessibility-scenarios
adamsamec Feb 3, 2022
8128639
Merge branch 'master' into accessibility-scenarios
adamsamec Feb 4, 2022
1c55025
Fix Tooltip error regarding relationship attribute
adamsamec Feb 4, 2022
06cc182
Merge branch 'master' into accessibility-scenarios
adamsamec Feb 8, 2022
d371644
Add uncomplete Input scenario
adamsamec Feb 8, 2022
576e8ec
Add slider component scenario and fix TS error in Input scenario
adamsamec Feb 8, 2022
7153067
Change files
adamsamec Feb 8, 2022
e2caadf
Fix import errors
adamsamec Feb 9, 2022
effff28
Add screen reader supported validation to input scenario form
adamsamec Feb 10, 2022
9571be7
Add lint disable next line for complex object
adamsamec Feb 10, 2022
74f98df
Rename labels in slider scenario
adamsamec Feb 10, 2022
643ddf9
Remove errorneously inserted unused declaration and import
adamsamec Feb 10, 2022
41efa6c
Merge branch 'master' into accessibility-scenarios2
adamsamec Feb 15, 2022
0ad7cfa
Replace <input> with <Input> and add <form>
adamsamec Feb 16, 2022
0671176
Remove already not needed import error ignore comments
adamsamec Feb 16, 2022
703885e
Add onBlur validation for Input scenario and changed input requiremen…
adamsamec Feb 16, 2022
8b48678
Replace 'any' with new type
adamsamec Feb 17, 2022
f25e9d1
Fix error messages flickering
adamsamec Feb 19, 2022
395b297
Add aria=invalid in Input scenario
adamsamec Feb 21, 2022
fe3da60
Fix nickname typo
adamsamec Feb 21, 2022
76895f1
Replace h1 heading with h2
adamsamec Feb 21, 2022
54224b7
Implement form validation using React Hook Form
adamsamec Mar 2, 2022
3d26d6f
Ignore line max length lint error and add react-hook-form dependency
adamsamec Mar 3, 2022
aed87de
Focus error element upon form submission and narrate when already foc…
adamsamec Mar 3, 2022
3702466
Change form revalidate to onBlur
adamsamec Mar 3, 2022
cdc1c17
Replace custom validation with React Hook Form library, but narration…
Mar 16, 2022
2833476
toggle alert role to force re-reading of errors
Mar 21, 2022
cdb3f7f
Merge master
Mar 22, 2022
2670641
fix narration on submit
Mar 24, 2022
344def2
Merge master
adamsamec Apr 4, 2022
3a035e8
Merge branch 'master' into accessibility-scenarios2
adamsamec Apr 5, 2022
9bd51d5
Merge branch 'master' into accessibility-scenarios2
adamsamec Apr 6, 2022
e2c1013
Fix onblur error narration instead of first error narration on submit
adamsamec Apr 7, 2022
aac3bc5
Remove pubsub dependancy which was moved to root
adamsamec Apr 7, 2022
102ebca
Merge branch 'master' into accessibility-scenarios2
adamsamec Apr 11, 2022
e72718c
Remove the password hint scenario for Tooltip component
adamsamec Apr 11, 2022
03324c3
fix lint issues
Apr 13, 2022
140f833
fix package
Apr 14, 2022
6f825f8
fix
Apr 14, 2022
0efa089
Merge branch 'master' into accessibility-scenarios2
adamsamec Apr 19, 2022
a610f5f
Merge remote-tracking branch 'origin/master' into accessibility-scena…
May 6, 2022
9e71aed
cleanup
May 6, 2022
a836ad7
Merge remote-tracking branch 'upstream/master' into accessibility-sce…
May 6, 2022
a3b0b89
Merge branch 'master' into accessibility-scenarios2
adamsamec May 27, 2022
fe387d4
Replace native checkbox with Checkbox Fluent UI component
adamsamec May 30, 2022
58abbc2
Fix typo in word 'reminder'
adamsamec May 30, 2022
88a2402
Add basic Checkbox scenario and consistency fixes in other scenarios
adamsamec May 30, 2022
cfa7fe0
Add other accessibility relevant variants of Checkbox
adamsamec May 31, 2022
c536ffa
Add temporary version of RadioGroup scenario and replace native HTML …
adamsamec May 31, 2022
7f6f997
Replace native HTML checkbox elements with Fluent UI components
adamsamec May 31, 2022
09c789e
Replace native HTML input with Fluent UI Input component
adamsamec May 31, 2022
14d624e
Merge branch 'master' into accessibility-scenarios2
adamsamec May 31, 2022
fa70233
Add disabled items variant for RadioGroup and some nit picking fixes …
adamsamec May 31, 2022
c6f1413
Add disabled RadioGroup variant
adamsamec May 31, 2022
2ff7962
Replace tabindex values from 0 to -1
adamsamec Jun 1, 2022
ff2a3cb
Add Spinner, Switch and TabList components scenarios
adamsamec Jun 9, 2022
4e507a5
Merge branch 'master' into accessibility-scenarios2
adamsamec Jun 13, 2022
d8847d4
Add disabled tab for TabList scenario
adamsamec Jun 13, 2022
0b4c4ab
Add Notifications tab for TabList scenario
adamsamec Jun 13, 2022
34bbe1d
Add Textarea scenarioand changes to TabList scenario
adamsamec Jun 14, 2022
e64cf33
Make checkboxes appear on a new line
adamsamec Jun 14, 2022
f827213
Make textareas appear on a new line
adamsamec Jun 14, 2022
bd1f47f
Add vertical and overflow variants of TabList scenarios and small ref…
adamsamec Jun 15, 2022
c541a5a
Merge branch 'master' into accessibility-scenarios2
adamsamec Jun 16, 2022
dcd8c03
Fix broken page with scenarios
adamsamec Jun 16, 2022
5729743
Merge branch 'master' into accessibility-scenarios2
adamsamec Jun 28, 2022
c096a8f
Merge branch 'master' into accessibility-scenarios2
adamsamec Jun 29, 2022
e8a827c
Add Input with placeholder attribute
adamsamec Jun 29, 2022
dba8542
Add disabled Input example and preparation for readonly Input
adamsamec Jun 30, 2022
4a0e234
Add lint ignore for long regex lines
adamsamec Jul 1, 2022
cdaef90
Merge branch 'master' into accessibility-scenarios2
adamsamec Jul 11, 2022
5eb301d
Make <input> readonly and small refactoring of security code generati…
adamsamec Jul 12, 2022
9e377f5
Merge branch 'master' into accessibility-scenarios2
adamsamec Jul 12, 2022
f0cf412
Proper setting of readOnly prpprop on Input component scenario
adamsamec Jul 13, 2022
648ec60
Merge branch 'master' into accessibility-scenarios2
adamsamec Jul 13, 2022
eea26d4
Merge branch 'master' into accessibility-scenarios2
adamsamec Jul 15, 2022
f42b95f
Merge branch 'master' into accessibility-scenarios2
adamsamec Jul 18, 2022
3ff0386
Add validation for Textarea scenario, add more variants and fix Input…
adamsamec Jul 19, 2022
a3abca2
include accessibility scenario stories in the public docs
Jul 26, 2022
cb065df
Merge branch 'master' into accessibility-scenarios2
adamsamec Jul 27, 2022
c4ead9e
Merge remote-tracking branch 'upstream/master' into accessibility-sce…
Aug 10, 2022
9f4fa25
Merge branch 'accessibility-scenarios2' of https://github.com/adamsam…
Aug 10, 2022
4c34a1f
fix imports
Aug 10, 2022
595b3ef
fix imports
Aug 10, 2022
a514ab2
Merge branch 'master' into accessibility-scenarios2
adamsamec Aug 15, 2022
6fea27a
Merge branch 'master' into accessibility-scenarios2
adamsamec Aug 31, 2022
cd91ac2
chore: add index.stories.tsx
bsunderhus Sep 1, 2022
8a4d6ca
Add FAQ accordion story
adamsamec Sep 1, 2022
c9b3b0a
Add first half of v9 accessibility scenarios
adamsamec Sep 6, 2022
9f764c9
Add remaining v9 accessibility scenarios
adamsamec Sep 6, 2022
ab951c7
Merge branch 'master' into accessibility-scenarios2
adamsamec Sep 12, 2022
031f48d
Make Send button not disabledFocusable
adamsamec Sep 12, 2022
13c5175
Make error message alerting more robust and remove 500ms setTimeout f…
adamsamec Sep 13, 2022
23ad675
Make overflow button in TabList not selected
adamsamec Sep 13, 2022
4185045
Fix email validating birthDay instead
adamsamec Sep 21, 2022
248ecf8
Merge branch 'master' into accessibility-scenarios2
adamsamec Sep 26, 2022
a3ae1ac
Fix email validation and some code cleaning
adamsamec Sep 26, 2022
83f6b2b
Fix first error field focus upon form submission problem
adamsamec Sep 27, 2022
752b3af
Merge branch 'master' into accessibility-scenarios2
adamsamec Oct 3, 2022
b74eee8
Make Input and Textarea scenarios more like a real example
adamsamec Oct 6, 2022
c74dbde
Merge branch 'master' into accessibility-scenarios2
adamsamec Oct 6, 2022
6b8addb
Fix email validation when not required
adamsamec Oct 6, 2022
7457228
Fix Input and Textarea scenario form validation and text changes
adamsamec Oct 6, 2022
6b92cda
Fix invalid disabled textarea bug
adamsamec Oct 6, 2022
62491f5
Merge remote-tracking branch 'upstream/master' into accessibility-sce…
Oct 19, 2022
7dafdfc
fix scenarios link, remove them from sidebar again
Oct 19, 2022
2903ab2
Update apps/public-docsite-v9/.storybook/main.utils.js
jurokapsiar Oct 21, 2022
d8aee38
fix md file change
Oct 21, 2022
03005ed
temporarily add `as` to MenuItem usage
Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/public-docsite-v9/.storybook/manager-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
Usign suggested temporary workaround until storybook gets proper support
See https://github.com/microsoft/fluentui/blob/master/rfcs/convergence/authoring-stories.md#10-internal-stories-for-testing
*/
[id*='accessibility-scenario'] {
[id*='accessibility-stories'] {
display: none !important;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Add uncomplete Input scenario",
"packageName": "@fluentui/react-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
Usign suggested temporary workaround until storybook gets proper support
See https://github.com/microsoft/fluentui/blob/master/rfcs/convergence/authoring-stories.md#10-internal-stories-for-testing
*/
[id*='accessibility-scenario'] {
[id*='accessibility-stories'] {
display: none !important;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,79 @@ import {
Button,
Input,
Label,
Radio,
RadioGroup,
Checkbox,
} from '@fluentui/react-components';

import { Scenario } from './utils';

export const PersonalFormAccordionAccessibilityScenario: React.FunctionComponent = () => {
export const PersonalFormAccordion = () => {
const [isSubmitted, setIsSubmitted] = React.useState(false);

React.useEffect(() => {
if (isSubmitted) {
document.getElementById('formSubmittedText')?.focus();
}
}, [isSubmitted]);

const onSubmit = (event: React.BaseSyntheticEvent) => {
event.preventDefault();
setIsSubmitted(true);
};

return (
<Scenario pageTitle="Personal form accordion">
<h1>Personal form</h1>
<form>
<Accordion defaultOpenItems="basicInfo">
<AccordionItem value="basicInfo">
<AccordionHeader as="h2">Basic information</AccordionHeader>
<AccordionPanel>
<Label htmlFor="name">Name:</Label>
<Input type="text" id="name" name="name" />
<Label htmlFor="email">Email:</Label>
<Input type="text" id="email" name="email" />
<fieldset>
<legend>Age</legend>
<input type="radio" id="ageClass1" name="age" value="ageClass1" />
<Label htmlFor="ageClass1">Below 18</Label>
<input type="radio" id="ageClass2" name="age" value="ageClass2" />
<Label htmlFor="ageClass2">Between 18 and 30</Label>
<input type="radio" id="ageClass3" name="age" value="ageClass3" />
<Label htmlFor="ageClass3">Over 30</Label>
</fieldset>
</AccordionPanel>
</AccordionItem>
<AccordionItem value="residence">
<AccordionHeader as="h2">Residence</AccordionHeader>
<AccordionPanel>
<Label htmlFor="street">Street:</Label>
<Input type="text" id="street" name="street" />
<Label htmlFor="city">City:</Label>
<Input type="text" id="city" name="city" />
<Label htmlFor="country">Country:</Label>
<Input type="text" id="country" name="country" />
</AccordionPanel>
</AccordionItem>
<AccordionItem value="hobbies">
<AccordionHeader as="h2">Hobbies</AccordionHeader>
<AccordionPanel>
<div role="group" aria-label="Hobbies">
<input type="checkbox" id="books" name="hobbies" value="books" />
<Label htmlFor="books">books</Label>
<input type="checkbox" id="sports" name="hobbies" value="sports" />
<Label htmlFor="sports">sports</Label>
<input type="checkbox" id="music" name="hobbies" value="music" />
<Label htmlFor="music">music</Label>
<input type="checkbox" id="travelling" name="hobbies" value="travelling" />
<Label htmlFor="travelling">travelling</Label>
</div>
</AccordionPanel>
</AccordionItem>
</Accordion>
<Button>Submit</Button>
</form>
{!isSubmitted ? (
<form onSubmit={onSubmit}>
<Accordion defaultOpenItems="basicInfo">
<AccordionItem value="basicInfo">
<AccordionHeader as="h2">Basic information</AccordionHeader>
<AccordionPanel>
<Label htmlFor="name">Name:</Label>
<Input type="text" id="name" name="name" />
<Label htmlFor="email">Email:</Label>
<Input type="email" id="email" name="email" />
<Label id="ageLabel">Your age:</Label>
<RadioGroup defaultValue="ageClass1" aria-labelledby="ageLabel">
<Radio value="ageClass1" label="Under 16" />
<Radio value="ageClass2" label="Between 16 and 50" />
<Radio value="ageClass3" label="Over 50" />
</RadioGroup>
</AccordionPanel>
</AccordionItem>
<AccordionItem value="residence">
<AccordionHeader as="h2">Residence</AccordionHeader>
<AccordionPanel>
<Label htmlFor="street">Street:</Label>
<Input type="text" id="street" name="street" />
<Label htmlFor="city">City:</Label>
<Input type="text" id="city" name="city" />
<Label htmlFor="country">Country:</Label>
<Input type="text" id="country" name="country" />
</AccordionPanel>
</AccordionItem>
<AccordionItem value="hobbies">
<AccordionHeader as="h2">Hobbies</AccordionHeader>
<AccordionPanel>
<div role="group" aria-labelledby="hobbiesLabel">
<Label id="hobbiesLabel">Please select your hobbies:</Label>
<Checkbox label="Books" />
<Checkbox label="Sports" />
<Checkbox label="Music" />
<Checkbox label="Travelling" />
</div>
</AccordionPanel>
</AccordionItem>
</Accordion>
<Button type="submit">Submit</Button>
</form>
) : (
<p id="formSubmittedText" tabIndex={-1}>
The form would have been submitted.
</p>
)}
</Scenario>
);
};

export default {
title: 'Accessibility Scenarios / Personal form accordion',
id: 'accordion-accessibility-scenario',
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Accordion, AccordionHeader, AccordionItem, AccordionPanel } from '@flue

import { Scenario } from './utils';

export const FAQAccordionAccessibilityScenario: React.FunctionComponent = () => {
export const FAQAccordion: React.FunctionComponent = () => {
return (
<Scenario pageTitle="FAQ accordion">
<h1>Frequently asked questions about Windows</h1>
Expand Down Expand Up @@ -53,8 +53,3 @@ export const FAQAccordionAccessibilityScenario: React.FunctionComponent = () =>
</Scenario>
);
};

export default {
title: 'Accessibility Scenarios / FAQ accordion',
id: 'accordion-faq-accessibility-scenario',
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Button } from '@fluentui/react-components';

import { Scenario } from './utils';

export const MessengerButtonsAccessibilityScenario: React.FunctionComponent = () => {
const [sendButtonDisabled, setSendButtonDisabled] = React.useState<boolean | undefined>(true);
export const MessengerButtons: React.FunctionComponent = () => {
const [deleteButtonDisabled, setDeleteButtonDisabled] = React.useState<boolean | undefined>(true);
const [increaseFontButtonDisabled, setIncreaseFontButtonDisabled] = React.useState<boolean | undefined>(undefined);
const [decreaseFontButtonDisabled, setDecreaseFontButtonDisabled] = React.useState<boolean | undefined>(true);
Expand All @@ -23,13 +22,16 @@ export const MessengerButtonsAccessibilityScenario: React.FunctionComponent = ()

const resetMessage = () => {
setMessage('');
setSendButtonDisabled(true);
setDeleteButtonDisabled(true);
};

const onSendButtonClick = () => {
if (message.length > 0) {
setStatusText('Message has been sent.');
} else {
setStatusText('Please type a message.');
}
resetMessage();
setStatusText('Message has been sent.');
};
const onDeleteButtonClick = () => {
resetMessage();
Expand Down Expand Up @@ -59,50 +61,38 @@ export const MessengerButtonsAccessibilityScenario: React.FunctionComponent = ()
const onMessageTextareaChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const value = event.target.value;
if (value.length > 0) {
setSendButtonDisabled(undefined);
setDeleteButtonDisabled(undefined);
setStatusText('');
} else {
setSendButtonDisabled(true);
setDeleteButtonDisabled(true);
}
setMessage(value);
};

return (
<Scenario pageTitle="Messenger buttons">
<Button disabledFocusable={sendButtonDisabled} onClick={onSendButtonClick}>
Send
</Button>
<Button disabledFocusable={deleteButtonDisabled} onClick={onDeleteButtonClick}>
Delete
</Button>
<Button ref={increaseFontButtonRef} disabled={increaseFontButtonDisabled} onClick={onIncreaseFontButtonClick}>
Increase font size
</Button>
<Button ref={decreaseFontButtonRef} disabled={decreaseFontButtonDisabled} onClick={onDecreaseFontButtonClick}>
Decrease font size
</Button>
<div>
<textarea
name="message"
rows={3}
cols={50}
placeholder="Enter message here...."
aria-label="Message"
onChange={onMessageTextareaChange}
value={message}
style={messageStyle}
/>
</div>
<p>
<span aria-live="polite">{statusText}</span>
</p>
<textarea
name="message"
rows={3}
cols={50}
placeholder="Enter message here...."
aria-label="Message"
onChange={onMessageTextareaChange}
value={message}
style={messageStyle}
/>
<Button onClick={onSendButtonClick}>Send</Button>
<Button disabledFocusable={deleteButtonDisabled} onClick={onDeleteButtonClick}>
Delete
</Button>

<p aria-live="polite">{statusText}</p>
</Scenario>
);
};

export default {
title: 'Accessibility Scenarios / Messenger buttons',
id: 'button-accessibility-scenario',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import * as React from 'react';

import { Button, Checkbox, CheckboxOnChangeData, Label } from '@fluentui/react-components';

import { Scenario } from './utils';

export const QuestionnaireAboutFoodCheckboxes: React.FunctionComponent = () => {
const [isAppleSelected, setIsAppleSelected] = React.useState(false);
const [isBananaSelected, setIsBananaSelected] = React.useState(false);
const [isOrangeSelected, setIsOrangeSelected] = React.useState(false);
const [isSpecialDietSelected, setIsSpecialDietSelected] = React.useState(false);
const [isSubmitted, setIsSubmitted] = React.useState(false);

const getSpecialDietDisabled = () => {
return isSpecialDietSelected ? false : true;
};

React.useEffect(() => {
if (isSubmitted) {
document.getElementById('formSubmittedText')?.focus();
}
}, [isSubmitted]);

const onSubmit = (event: React.BaseSyntheticEvent) => {
event.preventDefault();
setIsSubmitted(true);
};

return (
<Scenario pageTitle="Checkboxes in questionnaire about food">
<h1>Questionnaire about food</h1>
{!isSubmitted ? (
<form onSubmit={onSubmit}>
<div role="group" aria-labelledby="foodLabel">
<Label id="foodLabel">Select food that you like:</Label>

<Checkbox
checked={
isAppleSelected && isBananaSelected && isOrangeSelected
? true
: !(isAppleSelected || isBananaSelected || isOrangeSelected)
? false
: 'mixed'
}
onChange={(event: React.ChangeEvent, data: CheckboxOnChangeData) => {
setIsAppleSelected(!!data.checked);
setIsBananaSelected(!!data.checked);
setIsOrangeSelected(!!data.checked);
}}
label="All fruits"
/>
<Checkbox
checked={isAppleSelected}
onChange={() => setIsAppleSelected(checked => !checked)}
label="Apple"
/>
<Checkbox
checked={isBananaSelected}
onChange={() => setIsBananaSelected(checked => !checked)}
label="Banana"
/>
<Checkbox
checked={isOrangeSelected}
onChange={() => setIsOrangeSelected(checked => !checked)}
label="Orange"
/>
</div>

<Checkbox
checked={isSpecialDietSelected}
onChange={() => setIsSpecialDietSelected(checked => !checked)}
label="I am on special diet"
/>

<div role="group" aria-labelledby="cannotEatLabel">
<Label id="cannotEatLabel">I cannot eat the following:</Label>
<Checkbox disabled={getSpecialDietDisabled()} label="Sugar" />
<Checkbox disabled={getSpecialDietDisabled()} label="Meat" />
<Checkbox disabled={getSpecialDietDisabled()} label="Dairy products" />
</div>
<Checkbox
required
label={
<>
I accept the <a href="#">terms and conditions</a>.
</>
}
/>
<Button type="submit">Submit</Button>
</form>
) : (
<p id="formSubmittedText" tabIndex={-1}>
The form would have been submitted.
</p>
)}
</Scenario>
);
};
Loading