Skip to content

Commit

Permalink
Merge branch 'main' into tab-works-with-arrow-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
owenniblock authored Jun 28, 2022
2 parents c22437a + d09ea60 commit 0d18877
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-cats-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update Checkbox component to useIsomorphicLayoutEffect instead of useLayoutEffect to support SSR
5 changes: 5 additions & 0 deletions .changeset/cold-bottles-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Allow "falsely/empty" Autocomplete.Input values
5 changes: 5 additions & 0 deletions .changeset/dry-stingrays-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Add AutocompleteContext to Autocomplete component exports
58 changes: 58 additions & 0 deletions docs/content/Autocomplete.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,64 @@ const MultiSelectAddNewItem = () => {
render(<MultiSelectAddNewItem />)
```

#### Rendered with `Autocomplete.Context`

The `Autocomplete.Context` can be used to control the menu open/closed state and customize certain `Autocomplete` behaviors

```javascript live noinline
export function AutocompleteWithContext() {
return (
<Autocomplete>
<AutocompleteWithContextInternal />
</Autocomplete>
)
}

export function AutocompleteWithContextInternal() {
const autocompleteContext = useContext(Autocomplete.Context)
if (autocompleteContext === null) {
throw new Error('AutocompleteContext returned null values')
}

const {setShowMenu, showMenu} = autocompleteContext
const inputRef = useRef < HTMLInputElement > null
const [filterText, setFilterText] = useState('')

useEffect(() => {
if (!showMenu) {
// keep the menu open
setShowMenu(true)
}
}, [showMenu, setShowMenu])

const change = event => setFilterText?.(event.target.value)

return (
<Autocomplete.Context.Provider
value={{...autocompleteContext, autocompleteSuggestion: '', setAutocompleteSuggestion: () => false}}
>
<Autocomplete.Input ref={inputRef} value={filterText} onChange={change} />
<Autocomplete.Overlay>
<Autocomplete.Menu
items={[
{text: 'main', id: 0},
{text: 'autocomplete-tests', id: 1},
{text: 'a11y-improvements', id: 2},
{text: 'button-bug-fixes', id: 3},
{text: 'radio-input-component', id: 4},
{text: 'release-1.0.0', id: 5},
{text: 'text-input-implementation', id: 6},
{text: 'visual-design-tweaks', id: 7}
]}
selectedItemIds={[]}
selectionVariant="single"
/>
</Autocomplete.Overlay>
</Autocomplete.Context.Provider>
)
}
```
## Props
### Autocomplete.Input
Expand Down
2 changes: 1 addition & 1 deletion docs/content/NavList.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function NavItem({to, children}) {
const resolved = useResolvedPath(to)
const isCurrent = useMatch({path: resolved.pathname, end: true})
return (
<NavList.Item as={Link} to={to} aria-current={isCurrent ? 'page' : false}>
<NavList.Item as={Link} to={to} aria-current={isCurrent ? 'page' : undefined}>
{children}
</NavList.Item>
)
Expand Down
Loading

0 comments on commit 0d18877

Please sign in to comment.