Skip to content

Commit c83a06f

Browse files
authored
Add overlay props to Autocomplete.Overlay (#1967)
* Add overlay props to Autocomplete.Overlay * Improve documentation * Create ten-apes-smell.md
1 parent 2025036 commit c83a06f

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

.changeset/ten-apes-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Add overlay props to Autocomplete.Overlay

docs/content/Autocomplete.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ The `Autocomplete.Input` should not be rendered without a `<label>` who's `htmlF
2323

2424
### Autocomplete.Overlay
2525

26-
The `Autocomplete.Overlay` wraps the `Autocomplete.Menu` to display it in an [Overlay]() component.
26+
The `Autocomplete.Overlay` wraps the `Autocomplete.Menu` to display it in an [Overlay](./Overlay) component.
27+
This component takes the same props as the `Overlay` component.
2728
Most `Autocomplete` implementations will use the `Autocomplete.Overlay` component, but there could be special cases where the `Autocomplete.Menu` should be rendered directly after the `Autocomplete.Input` (for example: an `Autocomplete` that is already being rendered in an `Overlay`).
2829

2930
### Autocomplete.Menu

src/Autocomplete/AutocompleteOverlay.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ type AutocompleteOverlayInternalProps = {
1515
*/
1616
overlayProps?: Partial<OverlayProps>
1717
children?: React.ReactNode
18-
} & Pick<React.AriaAttributes, 'aria-labelledby'> // TODO: consider making 'aria-labelledby' required
18+
} & Partial<OverlayProps> &
19+
Pick<React.AriaAttributes, 'aria-labelledby'> // TODO: consider making 'aria-labelledby' required
1920

20-
function AutocompleteOverlay({menuAnchorRef, overlayProps, children}: AutocompleteOverlayInternalProps) {
21+
function AutocompleteOverlay({
22+
menuAnchorRef,
23+
overlayProps: oldOverlayProps,
24+
children,
25+
...newOverlayProps
26+
}: AutocompleteOverlayInternalProps) {
2127
const autocompleteContext = useContext(AutocompleteContext)
2228
if (autocompleteContext === null) {
2329
throw new Error('AutocompleteContext returned null values')
2430
}
31+
const overlayProps = {...oldOverlayProps, ...newOverlayProps}
2532
const {inputRef, scrollContainerRef, selectedItemLength, setShowMenu, showMenu = false} = autocompleteContext
2633
const {floatingElementRef, position} = useAnchoredPosition(
2734
{

src/stories/Autocomplete.stories.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,7 @@ export const WithCustomOverlayProps = () => {
558558
</Text>
559559
<Autocomplete>
560560
<Autocomplete.Input id="autocompleteInput" />
561-
<Autocomplete.Overlay
562-
overlayProps={{
563-
width: 'large',
564-
height: 'xsmall'
565-
}}
566-
>
561+
<Autocomplete.Overlay width="large" height="xsmall">
567562
<Autocomplete.Menu items={items} selectedItemIds={[]} aria-labelledby="autocompleteLabel" />
568563
</Autocomplete.Overlay>
569564
</Autocomplete>

0 commit comments

Comments
 (0)