I have been encountering an issue when using multiple select select fields within Safari 8 on OS X Yosemite. If the select field has an applied width, either in-line or as a class, I am unable to use the keyboards arrow keys to scroll down through the select as per normal behaviour.
<select size="5" name="selectMultiple" multiple="multiple">
Multiple select JSFiddle.
<select size="5" name="selectMultiple" multiple="multiple" style="width:100%;">
with style tag JSFiddle.
When the select has style the selection moves out of view instead of scrolling the list downwards keeping the selected item in view.
Is this a bug in the version of Safari (Version 8.0 (10600.1.25)) I am using. I am using BrowserStack for my testing. Or is this something I can address with a fix through my code?
Thank you.
I think this is indeed some type of bug that has to do with the width of the select element vs the scrollHeight of the element.
The more options you have, the wider it can be and still work fine. If I have a select tag with 39 options, the max seems to be around 510px before it messes up.
On average, the max width that a select can handle seems to be approx 13px per option. So if you have a selector with 13 options, then the max is about 169px (13 * 13)
When you scroll to the 2nd option, the scrollTop is 14px and to the 3rd option, 28px. So each element that you scroll to is 14px. So as long as the width is less than the scrollHeight minus a certain number of pixels, it works... If you use the 13 pixels per option, it seems to work fine.
So, you have 2 options.
OR
You just have to listen to the keydown event and adjust the scroll so that the selected element is in view before it is selected.
Also, in order to make the scrollByLines(numberOfLines) method work on the scroll element, it has to have the following style:
Here is a quick HTML document that works
And here is the jQuery version: