-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Autocomplete] fix adding items (pagination) causing scroll to go #30719
Conversation
to the top of the page
isPaginated and totalOptions
hi @kshitij-p, thanks for the effort i'm not sure what the general consensus w.r.t to this issue.
if (resetPosition && index === -1) {
listboxNode.scrollTop = 0;
return;
}
|
👋 The migration PR has been merged. Please follow these steps to make sure that the contents are all updated. (Sorry for the inconvenience)
If you are struggle with the steps above, feel free to tag @siriwatknp |
Any news of this? |
Sorry for not maintaining any communication, been a bit busy with college work. Finishing the steps mentioned above by siriwaktnp as of now. |
Hello, will this PR request be done when a maintainer approves? |
@kshitij-p Thanks for kicking off the PR. However, I feels like there should be a better way for the autocomplete to take care of this issue without the need for developers to use the props. For example, can we store the height of the list internally and then use it to compare with the new height (when more options are added), if the height is a lot more than some threshold then don't scroll. This is not 100% perfect but we don't need new props and it is easier to use. cc @michaldudak any idea? |
Hi, I also don't think adding new props is a good idea. The issue here is caused by logic that scrolls to the highlighted item whenever options change. It seems to me that we could remove the check: @@ -456,7 +460,7 @@ export default function useAutocomplete(props) {
const valueItem = multiple ? value[0] : value;
// The popup is empty, reset
- if (filteredOptions.length === 0 || valueItem == null) {
+ if (filteredOptions.length === 0) {
changeHighlightedIndex({ diff: 'reset' });
return;
}
To solve the problem appearing when using keyboard, I'm considering not firing const setHighlightedIndex = useEventCallback(({ event, index, reason = 'auto' }) => {
+ if (index === highlightedIndexRef.current) {
+ return;
+ }
+
highlightedIndexRef.current = index; It does, however, break some tests, so it would have to be explored further. One more thing to note - in the example from the issue it would be better to load more results before the scroll is at the very bottom. This is because highlighting the last item does not move the scroll to the bottom (there is some margin between the last item and the bottom of listbox), so highlighting the last item would not trigger loading additional items. |
@kshitij-p do you plan to continue the effort? If not, we can link @michaldudak's #30719 (comment) on the issue so that someone else could pick up and start working on it. |
No response in more than three weeks, I am closing this PR and linking #30719 (comment) on the issue |
Closes #30249
Link to a demo demonstrating the fix: DEMO
I have a few questions about the docs demo part-
Since my PR adds two new props:
Now the question is, do I need to write a demo for the isPaginated prop ? Because then I would have to write a demo for the docs with an implementation of the pagination that complies with keyboard accessibility and other concerns.