Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass onListboxScroll callback to SelectNext #1603

Merged
merged 1 commit into from
Jul 4, 2024
Merged
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
7 changes: 6 additions & 1 deletion src/components/input/SelectNext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classnames from 'classnames';
import type { ComponentChildren, RefObject } from 'preact';
import type { ComponentChildren, JSX, RefObject } from 'preact';
import {
useCallback,
useContext,
Expand Down Expand Up @@ -298,6 +298,9 @@ export type SelectProps<T> = CompositeProps &
* Defaults to true, as long as the browser supports it.
*/
listboxAsPopover?: boolean;

/** A callback passed to the listbox onScroll */
onListboxScroll?: JSX.HTMLAttributes<HTMLUListElement>['onScroll'];
};

function SelectMain<T>({
Expand All @@ -311,6 +314,7 @@ function SelectMain<T>({
buttonClasses,
listboxClasses,
containerClasses,
onListboxScroll,
right = false,
multiple = false,
'aria-label': ariaLabel,
Expand Down Expand Up @@ -460,6 +464,7 @@ function SelectMain<T>({
// handle boolean values correctly for this attribute (it will set
// `popover="false"` instead of removing the attribute).
popover={listboxAsPopover ? 'auto' : undefined}
onScroll={onListboxScroll}
>
{children}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,21 @@ export default function SelectNextPage() {
withSource
/>
</Library.Example>
<Library.Example title="onListboxScroll">
<Library.Info>
<Library.InfoItem label="description">
A callback passed to the listbox <code>onScroll</code>.
</Library.InfoItem>
<Library.InfoItem label="type">
<code>
() {'=>'} void {'|'} undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This callback actually receives an Event, although I'm not sure whether you want to promise that in the API.

</code>
</Library.InfoItem>
<Library.InfoItem label="default">
<code>undefined</code>
</Library.InfoItem>
</Library.Info>
</Library.Example>
</Library.Pattern>

<Library.Pattern title="SelectNext.Option component API">
Expand Down