-
Notifications
You must be signed in to change notification settings - Fork 513
feat(@clayui/autocomplete): LPD-55597 Improve infinite scrolling accessibility with SR announcements and visual feedback #6213
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
Merged
+430
−143
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
421b5d4
chore(storybook): LPD-55597 Add infinite scrolling examples
limaagabriel 58b4e47
feat(@clayui/autocomplete): LPD-55597 Add infinite scrolling SR annou…
limaagabriel 3a5bd11
feat(@clayui/autocomplete): LPD-55597 Add infinite scrolling trigger
limaagabriel 70fbbaf
feat(@clayui/autocomplete): LPD-55597 Allow infinite scrolling to aut…
limaagabriel 73bbecf
feat(@clayui/autocomplete): LPD-55597 Only announce when infinite scr…
limaagabriel 871edc1
feat(@clayui/autocomplete): LPD-55597 Change infinite scrolling so it…
limaagabriel 2ae4a85
docs(@clayui/autocomplete): LPD-55597 Add docstrings to the added props
limaagabriel 3ef8d49
chore(@clayui/autocomplete): LPD-55597 Rename variables for better cl…
limaagabriel 6a45768
chore(@clayui/autocomplete): LPD-55597 Fix type check and remove trig…
limaagabriel aa1be84
feat(@clayui/autocomplete): LPD-55597 Improve referential stability
limaagabriel 1c0d8d3
chore(@clayui/autocomplete): LPD-55597 Add infinite scrolling tests
limaagabriel 3c9aae4
feat(@clayui/autocomplete): LPD-55597 Avoid announcing initial load m…
limaagabriel 015669c
chore(@clayui/autocomplete): LPD-55597 Simplify onLoad message and re…
limaagabriel b10b0d0
chore(@clayui/autocomplete): LPD-55597 Remove batchLoadCount prop
limaagabriel 07163e1
feat(@clayui/autocomplete): LPD-55597 Remove unwanted auto scrolling
limaagabriel 35e3854
chore(@clayui/autocomplete): LPD-55597 Simplify announcement-related …
limaagabriel 697c1de
feat(@clayui/autocomplete): LPD-55597 Remove custom infinite scroll t…
limaagabriel 5e49a25
feat(@clayui/autocomplete): LPD-55597 Rollback to use Collection inif…
limaagabriel c118a44
chore(@clayui/autocomplete): LPD-55597 Simplify announcement-related …
limaagabriel ebd0dda
chore(@clayui/autocomplete): LPD-55597 Sort variable definitions
limaagabriel 394a85f
chore(@clayui/autocomplete): Fix case where navigating to the last it…
limaagabriel ffedef7
feat(@clayui/autocomplete): LPD-55597 Remove code to load more while …
limaagabriel 9b5be97
chore(@clayui/autocomplete): LPD-55597 Replace usage of magic number …
limaagabriel cc51f2c
feat(@clayui/autocomplete): LPD-55597 Enable infinite scroll for case…
limaagabriel 9c38154
chore(@clayui/autocomplete): LPD-55597 Add comments to the tests to i…
limaagabriel f558fd6
chore(@clayui/autocomplete): LPD-55597 Add data-provider package to t…
limaagabriel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: © 2025 Liferay, Inc. <https://liferay.com> | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| import {AnnouncerAPI} from '@clayui/core'; | ||
| import {CollectionState} from '@clayui/core/src/collection/types'; | ||
| import {NetworkStatus} from '@clayui/data-provider'; | ||
| import LoadingIndicator from '@clayui/loading-indicator'; | ||
| import {sub} from '@clayui/shared'; | ||
| import React, {RefObject, useCallback, useEffect, useRef} from 'react'; | ||
|
|
||
| import {AutocompleteMessages} from './Autocomplete'; | ||
|
|
||
| interface IProps { | ||
| /** | ||
| * Reference to the announcer API. | ||
| */ | ||
| announcer: RefObject<AnnouncerAPI>; | ||
|
|
||
| /** | ||
| * Flag to indicate if the autocomplete is active (i.e., the menu is open) | ||
| */ | ||
| active: boolean; | ||
|
|
||
| /** | ||
| * The collection state of the autocomplete items. | ||
| */ | ||
| collection: CollectionState; | ||
|
|
||
| /** | ||
| * Loading state of the autocomplete. | ||
| */ | ||
| loadingState?: number; | ||
|
|
||
| /** | ||
| * Localized messages for the autocomplete. | ||
| */ | ||
| messages: Required<AutocompleteMessages>; | ||
|
|
||
| /** | ||
| * Callback function to load more items. | ||
| */ | ||
| onLoadMore?: () => Promise<any> | null; | ||
| } | ||
|
|
||
| export function useInfiniteScroll({ | ||
| active, | ||
| announcer, | ||
| collection, | ||
| loadingState = NetworkStatus.Unused, | ||
| messages, | ||
| onLoadMore, | ||
| }: IProps) { | ||
| const currentCount = collection.getSize(); | ||
| const isInfiniteScrollEnabled = Boolean(onLoadMore); | ||
| const isLoading = Boolean(loadingState < NetworkStatus.Unused); | ||
|
|
||
| const isInitialLoadAnnouncementPending = useRef<boolean>( | ||
| isInfiniteScrollEnabled | ||
| ); | ||
| const lastCountAnnounced = useRef<number | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (active) { | ||
| if (isLoading) { | ||
| announcer.current?.announce(messages.infiniteScrollOnLoad); | ||
| lastCountAnnounced.current = null; | ||
| } else if (lastCountAnnounced.current !== currentCount) { | ||
| const singular = isInitialLoadAnnouncementPending.current | ||
| ? messages.infiniteScrollInitialLoad | ||
| : messages.infiniteScrollOnLoaded; | ||
|
|
||
| const plural = isInitialLoadAnnouncementPending.current | ||
| ? messages.infiniteScrollInitialLoadPlural | ||
| : messages.infiniteScrollOnLoadedPlural; | ||
|
|
||
| const message = sub(currentCount === 1 ? singular : plural, [ | ||
| currentCount, | ||
| ]); | ||
|
|
||
| announcer.current?.announce(message); | ||
| lastCountAnnounced.current = currentCount; | ||
| isInitialLoadAnnouncementPending.current = false; | ||
| } | ||
| } else { | ||
| isInitialLoadAnnouncementPending.current = isInfiniteScrollEnabled; | ||
| } | ||
| }, [active, isLoading, currentCount]); | ||
|
|
||
| const InfiniteScrollFeedback = useCallback( | ||
| () => | ||
| isInfiniteScrollEnabled && isLoading ? ( | ||
| <LoadingIndicator className="my-2" size="sm" /> | ||
| ) : null, | ||
| [isInfiniteScrollEnabled, isLoading] | ||
| ); | ||
|
|
||
| return InfiniteScrollFeedback; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.