Skip to content

Commit 9a4e46c

Browse files
authored
Bump behaviors to v1.10.0; adds new prop to FilteredActionList (#7436)
1 parent a86c183 commit 9a4e46c

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

.changeset/slow-seas-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
FilteredActionList: Adds new prop `scrollBehavior` to allow customization of scroll behavior

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"@github/tab-container-element": "^4.8.2",
8080
"@lit-labs/react": "1.2.1",
8181
"@oddbird/popover-polyfill": "^0.5.2",
82-
"@primer/behaviors": "^1.9.1",
82+
"@primer/behaviors": "^1.10.0",
8383
"@primer/live-region-element": "^0.7.1",
8484
"@primer/octicons-react": "^19.21.0",
8585
"@primer/primitives": "10.x || 11.x",

packages/react/src/FilteredActionList/FilteredActionList.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ export interface FilteredActionListProps extends Partial<Omit<GroupedListProps,
106106
* Default is false.
107107
*/
108108
focusPrependedElements?: boolean
109+
/**
110+
* Determines the scroll behavior of the container when an item is focused.
111+
*
112+
* @default 'auto'
113+
*/
114+
scrollBehavior?: ScrollBehavior
109115
}
110116

111117
export function FilteredActionList({
@@ -136,6 +142,7 @@ export function FilteredActionList({
136142
disableSelectOnHover = false,
137143
setInitialFocus = false,
138144
focusPrependedElements,
145+
scrollBehavior,
139146
...listProps
140147
}: FilteredActionListProps): JSX.Element {
141148
const [filterValue, setInternalFilterValue] = useProvidedStateOrCreate(externalFilterValue, undefined, '')
@@ -258,8 +265,11 @@ export function FilteredActionList({
258265
activeDescendantFocus: inputRef,
259266
onActiveDescendantChanged: (current, previous, directlyActivated) => {
260267
activeDescendantRef.current = current
261-
if (current && scrollContainerRef.current && directlyActivated) {
262-
scrollIntoView(current, scrollContainerRef.current, menuScrollMargins)
268+
if (current && scrollContainerRef.current && (directlyActivated || focusPrependedElements)) {
269+
scrollIntoView(current, scrollContainerRef.current, {
270+
...menuScrollMargins,
271+
behavior: scrollBehavior,
272+
})
263273
}
264274

265275
onActiveDescendantChanged?.(current, previous, directlyActivated)
@@ -276,10 +286,10 @@ export function FilteredActionList({
276286
if (activeDescendantRef.current && scrollContainerRef.current) {
277287
scrollIntoView(activeDescendantRef.current, scrollContainerRef.current, {
278288
...menuScrollMargins,
279-
behavior: 'auto',
289+
behavior: scrollBehavior,
280290
})
281291
}
282-
}, [items, inputRef, scrollContainerRef])
292+
}, [items, inputRef, scrollContainerRef, scrollBehavior])
283293

284294
useEffect(() => {
285295
if (usingRovingTabindex) {

0 commit comments

Comments
 (0)