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

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

Open
MBuchalik opened this issue Sep 7, 2019 · 17 comments · May be fixed by #30202
Open

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

MBuchalik opened this issue Sep 7, 2019 · 17 comments · May be 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? 👀🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.