Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-lamps-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Fix positioning of Autocomplete overlay menu when tokens are present
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.
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@
overflow: auto;
flex-grow: 1;
}

.InputWithStateLabel {
display: inline-flex;
align-items: flex-end;
gap: var(--base-size-24);
}

.StateLabelInline {
white-space: nowrap;
margin-bottom: var(--base-size-4);
}
37 changes: 21 additions & 16 deletions packages/react/src/Autocomplete/Autocomplete.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,22 +379,27 @@ export const WithCallbackWhenOverlayOpenStateChanges = () => {

return (
<Stack as="form" padding="normal">
<FormControl>
<FormControl.Label id="autocompleteLabel">Default label</FormControl.Label>
<Autocomplete>
<Autocomplete.Input />
<Autocomplete.Overlay>
<Autocomplete.Menu
items={items}
selectedItemIds={[]}
onOpenChange={onOpenChange}
aria-labelledby="autocompleteLabel"
/>
</Autocomplete.Overlay>
</Autocomplete>
</FormControl>
<div>
The menu is <strong>{isMenuOpen ? 'opened' : 'closed'}</strong>
<div className={classes.InputWithStateLabel}>
<div>
<FormControl>
<FormControl.Label id="autocompleteLabel">Default label</FormControl.Label>
<Autocomplete>
<Autocomplete.Input />
<Autocomplete.Overlay>
<Autocomplete.Menu
items={items}
selectedItemIds={[]}
onOpenChange={onOpenChange}
aria-labelledby="autocompleteLabel"
/>
</Autocomplete.Overlay>
</Autocomplete>
</FormControl>
</div>

<div className={classes.StateLabelInline}>
The menu is <strong>{isMenuOpen ? 'open' : 'closed'}</strong>
</div>
</div>
</Stack>
)
Expand Down
15 changes: 13 additions & 2 deletions packages/react/src/Autocomplete/AutocompleteOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type React from 'react'
import {useCallback, useContext} from 'react'
import {useCallback, useContext, useEffect, useRef} from 'react'
import {useAnchoredPosition} from '../hooks'
import type {OverlayProps} from '../Overlay'
import Overlay from '../Overlay'
Expand Down Expand Up @@ -37,11 +37,22 @@ function AutocompleteOverlay({
}
const overlayProps = {...oldOverlayProps, ...newOverlayProps}
const {inputRef, scrollContainerRef, selectedItemLength, setShowMenu, showMenu = false} = autocompleteContext

const computedAnchorRef = useRef<HTMLElement | null>(null)
useEffect(() => {
const explicit = menuAnchorRef?.current ?? null
const tokensContainer = inputRef.current
? (inputRef.current.closest('[data-prevent-token-wrapping]') as HTMLElement | null)
: null
const tokensRoot = tokensContainer?.parentElement ?? null
computedAnchorRef.current = explicit ?? tokensRoot ?? inputRef.current
}, [menuAnchorRef, inputRef])

const {floatingElementRef, position} = useAnchoredPosition(
{
side: 'outside-bottom',
align: 'start',
anchorElementRef: menuAnchorRef ? menuAnchorRef : inputRef,
anchorElementRef: computedAnchorRef as React.RefObject<HTMLElement>,
},
[showMenu, selectedItemLength],
)
Expand Down
Loading