Skip to content

Commit

Permalink
Merge branch 'main' of github.com:primer/react into mp/spinner-a11y
Browse files Browse the repository at this point in the history
  • Loading branch information
mperrotti committed Jan 11, 2024
2 parents 7448154 + c40f765 commit 54660f9
Show file tree
Hide file tree
Showing 69 changed files with 55 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-cooks-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

ActionMenu: Only use checkmarks in menus instead of checkboxes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/ActionList/ActionList.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,37 @@ export const MultiSelect = () => {
)
}

export const ListBoxMultiSelect = () => {
const [selectedIndices, setSelectedIndices] = React.useState<number[]>([0])
const handleSelect = (index: number) => {
if (selectedIndices.includes(index)) {
setSelectedIndices(selectedIndices.filter(i => i !== index))
} else {
setSelectedIndices([...selectedIndices, index])
}
}
return (
<ActionList selectionVariant="multiple" aria-label="Project">
{projects.map((project, index) => (
<ActionList.Item
key={index}
role="menuitemcheckbox"
selected={selectedIndices.includes(index)}
aria-checked={selectedIndices.includes(index)}
onSelect={() => handleSelect(index)}
disabled={index === 3 ? true : undefined}
>
<ActionList.LeadingVisual>
<TableIcon />
</ActionList.LeadingVisual>
{project.name}
<ActionList.Description variant="block">{project.scope}</ActionList.Description>
</ActionList.Item>
))}
</ActionList>
)
}

export const DisabledSelectedMultiselect = () => (
<ActionList selectionVariant="multiple" role="menu" aria-label="Project">
<ActionList.Item role="menuitemcheckbox" selected aria-checked disabled>
Expand Down
4 changes: 2 additions & 2 deletions src/ActionList/Selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Box from '../Box'

type SelectionProps = Pick<ActionListItemProps, 'selected'>
export const Selection: React.FC<React.PropsWithChildren<SelectionProps>> = ({selected}) => {
const {selectionVariant: listSelectionVariant} = React.useContext(ListContext)
const {selectionVariant: listSelectionVariant, role: listRole} = React.useContext(ListContext)
const {selectionVariant: groupSelectionVariant} = React.useContext(GroupContext)

/** selectionVariant in Group can override the selectionVariant in List root */
Expand All @@ -29,7 +29,7 @@ export const Selection: React.FC<React.PropsWithChildren<SelectionProps>> = ({se
}
}

if (selectionVariant === 'single') {
if (selectionVariant === 'single' || listRole === 'menu') {
return <LeadingVisualContainer>{selected && <CheckIcon />}</LeadingVisualContainer>
}

Expand Down
19 changes: 11 additions & 8 deletions src/ActionMenu/ActionMenu.examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ export const GroupsAndDescriptions = () => {
{name: 'FY23 - Q2', due: 'December 30, 2022', progress: 0},
]

const [selectedMilestone, setSelectedMilestone] = React.useState<(typeof milestones)[0] | undefined>()
const [selectedMilestone, setSelectedMilestone] = React.useState<(typeof milestones)[0] | undefined>(milestones[2])

return (
<ActionMenu open>
<ActionMenu.Button variant="default" trailingVisual={GearIcon}>
Milestone
<ActionMenu.Button variant="default">
<Box sx={{display: 'inline-block', color: 'fg.muted'}}>Milestone:</Box>{' '}
{selectedMilestone?.name || 'Make a selection'}
</ActionMenu.Button>
<ActionMenu.Overlay width="medium">
<ActionList selectionVariant="single" showDividers>
Expand Down Expand Up @@ -241,7 +242,7 @@ export const MixedSelection = () => {
export const MultipleSections = () => {
const items = [{name: 'Show code folding buttons'}, {name: 'Wrap lines'}, {name: 'Center content'}]

const [selectedMilestone, setSelectedMilestone] = React.useState<(typeof items)[0] | undefined>()
const [selectedMilestone, setSelectedMilestone] = React.useState<(typeof items)[0] | undefined>(items[0])

return (
<ActionMenu open>
Expand All @@ -250,7 +251,7 @@ export const MultipleSections = () => {
</ActionMenu.Anchor>
<ActionMenu.Overlay width="small">
<ActionList>
<ActionList.Group title="Raw file content">
<ActionList.Group title="Raw file content" selectionVariant="multiple">
<ActionList.Item onSelect={() => alert('Workflows clicked')}>Download</ActionList.Item>
<ActionList.Divider />
<ActionList.Item onSelect={() => alert('Workflows clicked')}>Jump to line</ActionList.Item>
Expand All @@ -272,9 +273,11 @@ export const MultipleSections = () => {
))}
</ActionList.Group>
<ActionList.Divider />
<ActionList.Item onSelect={() => alert('Delete file')} variant="danger">
Delete file
</ActionList.Item>
<ActionList.Group title="View options" selectionVariant="multiple">
<ActionList.Item onSelect={() => alert('Delete file')} variant="danger">
Delete file
</ActionList.Item>
</ActionList.Group>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
Expand Down
10 changes: 6 additions & 4 deletions src/ActionMenu/ActionMenu.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {ActionMenu, ActionList} from '../'
import {ActionMenu, ActionList, Box} from '../'
import {WorkflowIcon, ArchiveIcon, GearIcon, CopyIcon, RocketIcon, CommentIcon, BookIcon} from '@primer/octicons-react'

export default {
Expand Down Expand Up @@ -36,7 +36,7 @@ export const LinksAndActions = () => (
</ActionList.LeadingVisual>
</ActionList.Item>
<ActionList.Divider />
<ActionList.Group title="Github projects">
<ActionList.Group title="GitHub projects">
<ActionList.LinkItem href="/">
What&apos;s new
<ActionList.LeadingVisual>
Expand Down Expand Up @@ -75,7 +75,9 @@ export const SingleSelect = () => {

return (
<ActionMenu>
<ActionMenu.Button>Options: {selectedType.name}</ActionMenu.Button>
<ActionMenu.Button>
<Box sx={{color: 'fg.muted', display: 'inline-block'}}>Options:</Box> {selectedType.name}
</ActionMenu.Button>
<ActionMenu.Overlay width="auto">
<ActionList selectionVariant="single">
{options.map((options, index) => (
Expand All @@ -93,7 +95,7 @@ export const MultiSelect = () => {
type Option = {name: string; selected: boolean}

const [options, setOptions] = React.useState<Option[]>([
{name: 'Show code folding buttons', selected: false},
{name: 'Show code folding buttons', selected: true},
{name: 'Wrap lines', selected: false},
{name: 'Center content', selected: false},
])
Expand Down

0 comments on commit 54660f9

Please sign in to comment.