Skip to content

Commit

Permalink
Merge branch 'main' into fix/update-react-aria-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack authored Jul 25, 2023
2 parents 7b5a762 + ab2ecfb commit 80c11e0
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 66 deletions.
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.
7 changes: 5 additions & 2 deletions docs/content/Octicon.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import data from '../../src/Octicon/Octicon.docs.json'

## Example

```jsx live
```js
import {CheckIcon, XIcon} from '@primer/octicons-react'
;<>
```

```jsx live
<>
<Octicon icon={CheckIcon} size={32} color="success.fg" sx={{mr: 2}} />
<Octicon icon={XIcon} size={32} color="danger.fg" />
</>
Expand Down
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"@babel/plugin-proposal-optional-chaining": "7.21.0",
"@babel/plugin-transform-modules-commonjs": "7.21.2",
"@babel/preset-react": "7.22.5",
"@babel/preset-typescript": "7.21.5",
"@babel/preset-typescript": "7.22.5",
"@changesets/changelog-github": "0.4.8",
"@github/markdownlint-github": "^0.3.0",
"@github/prettier-config": "0.0.6",
Expand Down
8 changes: 6 additions & 2 deletions src/Autocomplete/AutocompleteOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Overlay, {OverlayProps} from '../Overlay'
import {ComponentProps} from '../utils/types'
import {AutocompleteContext} from './AutocompleteContext'
import {useRefObjectAsForwardedRef} from '../hooks/useRefObjectAsForwardedRef'
import VisuallyHidden from '../_VisuallyHidden'

type AutocompleteOverlayInternalProps = {
/**
Expand Down Expand Up @@ -49,7 +50,7 @@ function AutocompleteOverlay({
return null
}

return (
return showMenu ? (
<Overlay
returnFocusRef={inputRef}
preventFocusOnOpen={true}
Expand All @@ -58,14 +59,17 @@ function AutocompleteOverlay({
ref={floatingElementRef as React.RefObject<HTMLDivElement>}
top={position?.top}
left={position?.left}
visibility={showMenu ? 'visible' : 'hidden'}
sx={{
overflow: 'auto',
}}
{...overlayProps}
>
{children}
</Overlay>
) : (
// HACK: This ensures AutocompleteMenu is still mounted when closing the menu and all of the hooks inside of it are still called.
// A better way to do this would be to move the hooks to AutocompleteOverlay or somewhere that won't get unmounted.
<VisuallyHidden aria-hidden="true">{children}</VisuallyHidden>
)
}

Expand Down
12 changes: 6 additions & 6 deletions src/Button/Button.dev.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export const TestSxProp = () => {
<Button
size="medium"
sx={{
color: 'deeppink',
color: 'firebrick',
}}
>
Medium Pink
Medium Red
</Button>
<Button
size="small"
Expand All @@ -61,14 +61,14 @@ export const TestSxProp = () => {
},
},
'@media (min-width: 1440)': {
color: 'deeppink',
color: 'firebrick',
},
}}
>
Pink
Red
</Button>
<Button leadingIcon={SearchIcon} variant="invisible" sx={{color: 'deeppink'}}>
Pink
<Button leadingIcon={SearchIcon} variant="invisible" sx={{color: 'firebrick'}}>
Red
</Button>
<Button
size="small"
Expand Down
2 changes: 1 addition & 1 deletion src/CheckboxGroup/CheckboxGroup.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
]
},
{
"name": "CheckboxGroup.Description",
"name": "CheckboxGroup.Caption",
"props": [
{
"name": "children",
Expand Down
4 changes: 2 additions & 2 deletions src/Token/Token.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const IssueLabelTokenCustomColors = () => {
text="Link"
fillColor="#0366d6"
/>
<IssueLabelToken as="button" onClick={action('clicked')} text="Button" fillColor="deeppink" />
<IssueLabelToken as="button" onClick={action('clicked')} text="Button" fillColor="lightpink" />
<IssueLabelToken as="span" tabIndex={0} onFocus={action('focused')} text="Focusable Span" fillColor="coral" />
</Box>
<h3>Color examples</h3>
Expand Down Expand Up @@ -276,7 +276,7 @@ export const IssueLabelTokenCustomColors = () => {
as="a"
href="/?path=/story/components-token-features--issue-label-token-custom-colors"
text="💡 Light"
fillColor="#f2107d"
fillColor="#E40C74"
/>
</Box>
</Box>
Expand Down
30 changes: 16 additions & 14 deletions src/__tests__/Autocomplete.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,28 +272,30 @@ describe('Autocomplete', () => {
<LabelledAutocomplete menuProps={{items: mockItems, selectedItemIds: [], selectionVariant: 'multiple'}} />,
)
const inputNode = container.querySelector('#autocompleteInput')
const itemToClickNode = getByText(mockItems[1].text)

expect(inputNode?.getAttribute('aria-expanded')).not.toBe('true')
inputNode && fireEvent.focus(inputNode)
expect(inputNode?.getAttribute('aria-expanded')).toBe('true')
fireEvent.click(itemToClickNode)
inputNode && (await user.type(inputNode, '{enter}'))
expect(inputNode?.getAttribute('aria-expanded')).toBe('true')
if (inputNode) {
expect(inputNode.getAttribute('aria-expanded')).not.toBe('true')
await user.click(inputNode)
expect(inputNode.getAttribute('aria-expanded')).toBe('true')
await user.click(getByText(mockItems[1].text))
expect(inputNode.getAttribute('aria-expanded')).toBe('true')
}
})

it('closes the menu when clicking an item in the menu if selectionVariant=single', () => {
it('closes the menu when clicking an item in the menu if selectionVariant=single', async () => {
const user = userEvent.setup()
const {getByText, container} = HTMLRender(
<LabelledAutocomplete menuProps={{items: mockItems, selectedItemIds: [], selectionVariant: 'single'}} />,
)
const inputNode = container.querySelector('#autocompleteInput')
const itemToClickNode = getByText(mockItems[1].text)

expect(inputNode?.getAttribute('aria-expanded')).not.toBe('true')
inputNode && fireEvent.focus(inputNode)
expect(inputNode?.getAttribute('aria-expanded')).toBe('true')
fireEvent.click(itemToClickNode)
expect(inputNode?.getAttribute('aria-expanded')).not.toBe('true')
if (inputNode) {
expect(inputNode.getAttribute('aria-expanded')).not.toBe('true')
await user.click(inputNode)
expect(inputNode.getAttribute('aria-expanded')).toBe('true')
await user.click(getByText(mockItems[1].text))
expect(inputNode.getAttribute('aria-expanded')).not.toBe('true')
}
})

it('calls handleAddItem with new item data when passing addNewItem', () => {
Expand Down
15 changes: 10 additions & 5 deletions src/hooks/useDialog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useCallback, useEffect} from 'react'
import {useOnEscapePress} from './useOnEscapePress'

const noop = () => null

Expand Down Expand Up @@ -103,19 +104,23 @@ function useDialog({
case 'Tab':
handleTab(event)
break
case 'Escape':
onDismiss()
event.stopPropagation()
break
}
},
[handleTab, onDismiss],
[handleTab],
)

const getDialogProps = () => {
return {onKeyDown}
}

useOnEscapePress(
(event: KeyboardEvent) => {
onDismiss()
event.preventDefault()
},
[onDismiss],
)

return {getDialogProps}
}

Expand Down
4 changes: 2 additions & 2 deletions src/stories/Autocomplete.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,8 @@ export const InADialog = (args: FormControlArgs<AutocompleteArgs>) => {

return (
<>
<Button onClick={() => setIsDialogOpen(!isDialogOpen)}>Show dialog</Button>
<Dialog id="dialog-with-autocomplete" isOpen={isDialogOpen}>
<Button onClick={() => setIsDialogOpen(true)}>Show dialog</Button>
<Dialog id="dialog-with-autocomplete" isOpen={isDialogOpen} onDismiss={() => setIsDialogOpen(false)}>
<div ref={outerContainerRef}>
<Box as="form" sx={{p: 3}}>
{mounted ? (
Expand Down
23 changes: 18 additions & 5 deletions src/stories/useFocusZone.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,23 @@ export const SpecialSituations = () => {
borderStyle="solid"
borderRadius={2}
>
<strong>Bound keys: Up, Down, PageUp, PageDown, W, S, J, K, Home, End, Tab</strong>
<strong id="focus-label">Bound keys: Up, Down, PageUp, PageDown, W, S, J, K, Home, End, Tab</strong>
<Box display="flex" flexDirection="column" alignItems="flex-start">
<input style={{width: '250px'}} type="text" defaultValue="Printable characters won't move focus" />
<input
style={{width: '250px'}}
type="text"
defaultValue="Printable characters won't move focus"
aria-labelledby="focus-label"
/>

<MarginButton>Regular button</MarginButton>
<select>
<select aria-labelledby="focus-label">
<option>Down arrow invokes dropdown</option>
<option>Unless Cmd (mac)/Ctrl (Windows)</option>
<option>Is held</option>
</select>
<textarea
aria-labelledby="focus-label"
style={{width: '250px', height: '95px'}}
defaultValue="Up/Down only works when at beginning/end. PageUp and PageDown completely disabled. Printable characters will never move focus."
></textarea>
Expand All @@ -426,11 +433,14 @@ export const SpecialSituations = () => {
borderStyle="solid"
borderRadius={2}
>
<strong>Use Left Arrow and Right Arrow to move focus within this box. Focus is circular.</strong>
<label htmlFor="focus-input">
<strong>Use Left Arrow and Right Arrow to move focus within this box. Focus is circular.</strong>
</label>

<Box display="flex" flexDirection="row" alignItems="center">
<MarginButton>Grapefruit</MarginButton>
<input
id="focus-input"
style={{width: '300px'}}
type="text"
defaultValue="Left/Right only work at beginning/end of input."
Expand Down Expand Up @@ -615,13 +625,16 @@ export const ActiveDescendant = () => {
<MarginButton>Banana</MarginButton>
<MarginButton>Cantaloupe</MarginButton>
<Box borderColor="gray.5" m={4} p={4} borderWidth="1px" borderStyle="solid" borderRadius={2}>
<strong>Bound keys: Arrow Up and Arrow Down</strong>
<label htmlFor="focus-input">
<strong>Bound keys: Arrow Up and Arrow Down</strong>
</label>
<Box display="flex" flexDirection="column" alignItems="flex-start">
<input
ref={controllingElementRef as React.RefObject<HTMLInputElement>}
type="text"
defaultValue="Focus remains here."
aria-controls="list"
id="focus-input"
/>
<Box
display="flex"
Expand Down

0 comments on commit 80c11e0

Please sign in to comment.