-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(Indeterminate Checkbox): Fixed issue with voice over not recognizing the mixed state when using keyboard navigation. #1652
Open
chris-cedrone-cengage
wants to merge
3
commits into
dev
Choose a base branch
from
bugfix/indeterminateCheckbox
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
β92
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'react-magma-dom': patch | ||
--- | ||
|
||
fix(Indeterminate Checkbox): Fixed issue with voice over not recognizing the mixed state when using keyboard navigation. |
198 changes: 106 additions & 92 deletions
198
...es/react-magma-dom/src/components/IndeterminateCheckbox/IndeterminateCheckbox.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,141 @@ | ||
import React from 'react'; | ||
import { Card, CardBody } from '../Card'; | ||
import { Container } from '../Container'; | ||
import { Checkbox } from '../Checkbox'; | ||
import { FormGroup } from '../FormGroup'; | ||
import { | ||
IndeterminateCheckbox, | ||
IndeterminateCheckboxStatus, | ||
} from '../IndeterminateCheckbox'; | ||
import { magma } from '../../theme/magma'; | ||
import { Meta } from '@storybook/react/types-6-0'; | ||
import { Story, Meta } from '@storybook/react/types-6-0'; | ||
import { IndeterminateCheckboxProps } from '../../../dist'; | ||
|
||
const Template: Story<IndeterminateCheckboxProps> = args => ( | ||
<FormGroup labelText="Indeterminate Checkbox Examples"> | ||
<IndeterminateCheckbox | ||
{...args} | ||
color={magma.colors.primary} | ||
defaultChecked={true} | ||
labelText="Indeterminate checkbox" | ||
id="0" | ||
/> | ||
<IndeterminateCheckbox | ||
{...args} | ||
disabled | ||
defaultChecked={true} | ||
labelText="Disabled indeterminate checkbox" | ||
id="1" | ||
/> | ||
<IndeterminateCheckbox | ||
{...args} | ||
defaultChecked={true} | ||
labelText="Error indeterminate checkbox" | ||
id="2" | ||
errorMessage="Error" | ||
/> | ||
</FormGroup> | ||
); | ||
|
||
export default { | ||
component: IndeterminateCheckbox, | ||
title: 'Indeterminate Checkbox', | ||
argTypes: { | ||
status: { | ||
control: { type: 'select' }, | ||
options: IndeterminateCheckboxStatus, | ||
}, | ||
isInverse: { | ||
control: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
decorators: [ | ||
(Story, context) => ( | ||
<Container isInverse={context.args.isInverse} style={{ padding: '20px' }}> | ||
<Story /> | ||
</Container> | ||
), | ||
], | ||
} as Meta; | ||
|
||
export const Default = () => { | ||
return ( | ||
<FormGroup labelText="Indeterminate Checkbox Examples"> | ||
<IndeterminateCheckbox | ||
color={magma.colors.primary} | ||
defaultChecked={true} | ||
status={IndeterminateCheckboxStatus.indeterminate} | ||
labelText="Indeterminate checkbox" | ||
id="0" | ||
/> | ||
<IndeterminateCheckbox | ||
disabled | ||
defaultChecked={true} | ||
status={IndeterminateCheckboxStatus.indeterminate} | ||
labelText="Disabled indeterminate checkbox" | ||
id="1" | ||
/> | ||
<IndeterminateCheckbox | ||
defaultChecked={true} | ||
status={IndeterminateCheckboxStatus.indeterminate} | ||
labelText="Error indeterminate checkbox" | ||
id="2" | ||
errorMessage="Error" | ||
/> | ||
</FormGroup> | ||
); | ||
}; | ||
|
||
export const Inverse = () => { | ||
return ( | ||
<Card isInverse> | ||
<CardBody> | ||
<FormGroup | ||
labelText="Inverse Indeterminate Checkbox Examples" | ||
isInverse | ||
> | ||
<IndeterminateCheckbox | ||
isInverse | ||
labelText="Indeterminate checkbox inverse" | ||
status={IndeterminateCheckboxStatus.indeterminate} | ||
id="3" | ||
/> | ||
<IndeterminateCheckbox | ||
disabled | ||
isInverse | ||
labelText="Disabled indeterminate checkbox inverse" | ||
status={IndeterminateCheckboxStatus.indeterminate} | ||
id="4" | ||
/> | ||
<IndeterminateCheckbox | ||
isInverse | ||
labelText="Error indeterminate checkbox" | ||
status={IndeterminateCheckboxStatus.indeterminate} | ||
id="5" | ||
errorMessage="Error" | ||
/> | ||
</FormGroup> | ||
</CardBody> | ||
</Card> | ||
); | ||
}; | ||
export const Default = Template.bind({}); | ||
Default.args = {}; | ||
|
||
export const Behavior = () => { | ||
const [checkedItems, setCheckedItems] = React.useState<Array<boolean>>([ | ||
true, | ||
false, | ||
false, | ||
false, | ||
]); | ||
|
||
const status: IndeterminateCheckboxStatus = checkedItems.every(Boolean) | ||
? IndeterminateCheckboxStatus.checked | ||
: checkedItems.some(Boolean) | ||
? IndeterminateCheckboxStatus.indeterminate | ||
: IndeterminateCheckboxStatus.unchecked; | ||
const [status, setStatus] = React.useState<IndeterminateCheckboxStatus>( | ||
IndeterminateCheckboxStatus.indeterminate | ||
); | ||
|
||
function getStatus(items: Array<boolean>) { | ||
return items.every(Boolean) | ||
? IndeterminateCheckboxStatus.checked | ||
: items.some(Boolean) | ||
? IndeterminateCheckboxStatus.indeterminate | ||
: IndeterminateCheckboxStatus.unchecked; | ||
} | ||
|
||
function handleUpdateIndeterminateChecked( | ||
event: React.ChangeEvent<HTMLInputElement> | ||
) { | ||
setCheckedItems([event.target.checked, event.target.checked]); | ||
const updatedCheckedItems = Array(4).fill(event.target.checked); | ||
setCheckedItems(updatedCheckedItems); | ||
setStatus(getStatus(updatedCheckedItems)); | ||
} | ||
|
||
function handleUpdateRedChecked(event: React.ChangeEvent<HTMLInputElement>) { | ||
setCheckedItems([event.target.checked, checkedItems[1]]); | ||
} | ||
|
||
function handleUpdateBlueChecked(event: React.ChangeEvent<HTMLInputElement>) { | ||
setCheckedItems([checkedItems[0], event.target.checked]); | ||
function handleColorChecked( | ||
index: number, | ||
event: React.ChangeEvent<HTMLInputElement> | ||
) { | ||
const updatedCheckedItems = [...checkedItems]; | ||
updatedCheckedItems[index] = event.target.checked; | ||
setCheckedItems(updatedCheckedItems); | ||
setStatus(getStatus(updatedCheckedItems)); | ||
} | ||
|
||
return ( | ||
<> | ||
<IndeterminateCheckbox | ||
onChange={handleUpdateIndeterminateChecked} | ||
status={status} | ||
labelText="Colors" | ||
id="5" | ||
/> | ||
<div style={{ marginLeft: magma.spaceScale.spacing08 }}> | ||
<Checkbox | ||
checked={checkedItems[0]} | ||
onChange={handleUpdateRedChecked} | ||
labelText="Red" | ||
/> | ||
<Checkbox | ||
checked={checkedItems[1]} | ||
onChange={handleUpdateBlueChecked} | ||
labelText="Blue" | ||
<FormGroup labelText="Colors group" isTextVisuallyHidden> | ||
<IndeterminateCheckbox | ||
onChange={handleUpdateIndeterminateChecked} | ||
status={status} | ||
labelText="Colors" | ||
id="indeterminateCheckbox" | ||
/> | ||
</div> | ||
<div style={{ marginLeft: magma.spaceScale.spacing08 }}> | ||
<Checkbox | ||
checked={checkedItems[0]} | ||
onChange={e => handleColorChecked(0, e)} | ||
labelText="Red" | ||
id="Red" | ||
/> | ||
<Checkbox | ||
checked={checkedItems[1]} | ||
onChange={e => handleColorChecked(1, e)} | ||
labelText="Blue" | ||
id="Blue" | ||
/> | ||
<Checkbox | ||
checked={checkedItems[2]} | ||
onChange={e => handleColorChecked(2, e)} | ||
labelText="Green" | ||
id="Green" | ||
/> | ||
<Checkbox | ||
checked={checkedItems[3]} | ||
onChange={e => handleColorChecked(3, e)} | ||
labelText="Yellow" | ||
id="Yellow" | ||
/> | ||
</div> | ||
</FormGroup> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay to have aria-checked twice? If it is, we can copy line 153
aria-checked={ariaCheckedValue}
.We have
type="checkbox"
on the hidden input so I worry this is repetitive??