Skip to content

feat: Auto scroll to selected item in ion-select #19296

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

Closed
MBuchalik opened this issue Sep 7, 2019 · 18 comments · Fixed by #30202
Closed

feat: Auto scroll to selected item in ion-select #19296

MBuchalik opened this issue Sep 7, 2019 · 18 comments · Fixed by #30202
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement

Comments

@MBuchalik
Copy link

Feature Request

Ionic version:

[x] 4.8.0

Describe the Feature Request

When a select menu (ion-select) contains many options so that it is scrollable, it is always scrolled to the top when the user opens it. If an option was already selected before opening it, the menu should start at this point.

You can see the following behavior on the Ionic Docs.

I have selected "September" here:

Screenshot_2019-09-07 ion-select - Ionic Documentation

Now, when opening the menu, the user doesn't see the selected item

Screenshot_2019-09-07 ion-select - Ionic Documentation(1)

Until he scrolls down:
Screenshot_2019-09-07 ion-select - Ionic Documentation(2)

Describe Preferred Solution

When opening a select menu, it should automatically scroll to the currently selected option. Not scrolling to this option might lead to confusion among the users: It is not clear if something was already selected and which item it was.

Please note that the behavior I observed applies not only to the "alert" select menu, but also to all other possible menu types, such as the popover.

Describe Alternatives

To be honest, I don't really know any alternatives to my suggestion.

Related Code

See the Ionic docs: https://ionicframework.com/docs/api/select

Additional Context

It was already reported a few years ago: in #8688 and #6356.

@ionitron-bot ionitron-bot bot added the triage label Sep 7, 2019
@liamdebeasi liamdebeasi added package: core @ionic/core package type: feature request a new feature, enhancement, or improvement labels Sep 10, 2019
@ionitron-bot ionitron-bot bot removed the triage label Sep 10, 2019
@indraraj26
Copy link

This should tag to bug instead of feature request. This is not user friendly for user it should fix immediately.

@MBuchalik
Copy link
Author

@indraraj26
I wasn't sure if this should be considered a feature request or bug report. You can indeed consider this an "UX bug", similar to how it was called in the discussion in #6356, since it is something that everyone expects from a select menu. (As it is something really basic... Everyone interacts with select menus every day and they all behave in the same way.)

@liamdebeasi Should we label this as a bug instead?

@anelad
Copy link

anelad commented Nov 22, 2019

@MBuchalik You say

You can indeed consider this an "UX bug"

Since Ionic is a UI framework, yes this is nothing but a bug.

@Rehan1579
Copy link

Still facing the issue in Ionic 5.x
Any update ?

@ankitasingh-12
Copy link

Is it fix? if yes in which version.

@davidgeary
Copy link

For anybody using Angular, I've created a workaround based on a hack I saw for this for a previous version of Ionic. It's an attribute directive targeting ionSelects that finds the selected option and scrolls it into view.

It works for all three of the ionSelect interfaces and just referencing it in your app's module should apply it to all ionSelects, without needing to update your templates (so when this is fixed properly in Ionic ;-), it'll be easy to remove).

@Rehan1579
Copy link

@davidgeary can you prepare a live example for it, it would be very helpful for all of us who face such issue.

@davidgeary
Copy link

@Rehan1579 There's not really much to show. It's an attribute directive, so you just need to add it to the declarations array of your AppModule (or any other relevant module in your app) and it should then be automatically applied to any ion-select in your component templates without any other changes.

@JorisDebonnet
Copy link

JorisDebonnet commented Apr 28, 2021

For what it's worth, I also created a directive that enables this much desired functionality. See on StackOverflow here.

@pankajjain15
Copy link

@JorisDebonnet I have implemented you solution but it shows scrolling to selected item . How to avoid that. I mean for e.g. if you have drop down of year 1900 to 2100 and selected value is 2021 . When I click on drop down , it opens up with 1900 and then suddenly it shows 2021. What it needs to show 2021 directly ? Kindly reply.

@JorisDebonnet
Copy link

When I click on drop down , it opens up with 1900 and then suddenly it shows 2021. What it needs to show 2021 directly ? Kindly reply.

I'm afraid it's not possible to immediately show the selected option (until this issue is resolved, inside the Ionic core). For now, we can only create workarounds by jumping to the selected option immediately after the dialog is opened.

@pankajjain15
Copy link

Thank you so much @JorisDebonnet . Really appreciate you quick reply.

@twilson-isi
Copy link

Jumping in to say that my client is perceiving this issue as a bug in their user testing, and I agree. This is a UX issue that still needs to be resolved in the core library.

@twilson-isi
Copy link

For posterity, I was able to solve this by using the following code (works if you're using the alert presentation for ion-select):

window.addEventListener('ion-alert-will-present', () => {
	let selectedOption = null
	const options = document.getElementsByClassName('alert-radio-button')
	if(options.length) {
		for(const option of options) {
		  const attribute = option.attributes.getNamedItem('aria-checked')
		  if(attribute && attribute.value === 'true') {
			selectedOption = option
			break
		  }
		}
	}
	if(selectedOption) {
		setTimeout(() => {
		  selectedOption.scrollIntoView({ block: 'center' })
		}, 0)
	}
}

@shonsirsha
Copy link

I feel like this is a basic yet very crucial feature. Any plans on the development of this feature yet?

At the moment, I'm using a hackish solution, similar to the above. However, it scrolls a little bit late (like 1 sec delay) and thus feels a little buggy.

Anyone able to achieve this auto scrolling without noticable delay?

@liamdebeasi liamdebeasi added type: feature request a new feature, enhancement, or improvement and removed type: feature request a new feature, enhancement, or improvement labels Oct 17, 2022
@dkern
Copy link

dkern commented May 31, 2023

This bug is still present after nearly 4 years. The selects are currently not really useful for longer lists because of this.

@Marius-Romanus
Copy link

Could version 8 be a good time for them to add that feature? 👀🤔

github-merge-queue bot pushed a commit that referenced this issue Feb 28, 2025
Issue number: resolves #19296

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->
- when the ion-select is with the interface action-sheet or alert is not
scrolling to the selected item on open

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->
- change test page so all select have scroll;
- guarantee focusVisibleElement is called on all interfaces;

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

---------

Co-authored-by: Brandy Smith <[email protected]>
Copy link

ionitron-bot bot commented Mar 30, 2025

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Mar 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.