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

Select list dropdown scrollbar closes the dropdown. #901

Closed
MattgyverHub opened this issue Mar 12, 2015 · 33 comments
Closed

Select list dropdown scrollbar closes the dropdown. #901

MattgyverHub opened this issue Mar 12, 2015 · 33 comments

Comments

@MattgyverHub
Copy link

I have a select list of US states which requires a scrollbar to limit the items shown to 7 or so. However, using the scrollbar immediately closes the droplist. The folks at the Angular/material git have a fix, but I don't understand how to implement it for the select list dropdown. Thanks in advance! angular/material#1739 The following is exactly what's happening:
9202f166-c03f-11e4-9404-e85da611d0b5

@Dogfalo
Copy link
Owner

Dogfalo commented Mar 13, 2015

The scrollbar on dropdowns worked for me on Chrome + OSX. What browser/OS are you on?

@MattgyverHub
Copy link
Author

Chrome on Windows 7 with the latest release build of Materialize v0.95.3. I set the height on the list to 200px, and made sure the overflow was on auto. Perhaps there is a better way to display the scrollbar by limiting the list items shown, instead of using a css height?

@Dahkon
Copy link

Dahkon commented May 15, 2015

Same problem for me.
It happend on all browser.

The problem is located here :
$newSelect.on('blur', function(){
$(this).trigger('close');
});

The blur event is fired once we click on the scrollbar.

@emurselovic
Copy link

Is this issue resolved?

If it is resolved where i can find solution.

@Pat-Paran
Copy link

I did this and it works Fine

// $newSelect.on('blur', function(){
// // $(this).trigger('close');
//
// });
$('.select-dropdown').find('span').on('click',function(){
$newSelect.trigger('close');
});

Comment out the on blur after that every click of options will get the value and close the dropdown.

@Pat-Paran
Copy link

if you want to exit the dropdown when you click outside Use this.
$(document).mouseup(function (e)
{
var container = $(".select-dropdown");

        if (!container.is(e.target) // if the target of the click isn't the container...
            && container.has(e.target).length === 0) // ... nor a descendant of the container
        {
           $newSelect.trigger('close');
        }
    });

@emurselovic
Copy link

Thank you very much. It is working as expected.

@chi-bd
Copy link

chi-bd commented Nov 17, 2015

Only to add the following '+' code after $('select').material_select(), without any patch to materialize.js.
(refer to https://code.google.com/p/chromium/issues/detail?id=51469)

  $(document).ready(function() {
    $('select').material_select();

+    var onMouseDown = function(e) {
+      // preventing the default still allows the scroll, but blocks the blur.
+      // We're inside the scrollbar if the clientX is >= the clientWidth.
+      if (e.clientX >= e.target.clientWidth || e.clientY >= e.target.clientHeight) {
+        e.preventDefault();
+      }
+    };
+    //$newSelect.on('mousedown', onMouseDown);
+    $(’select').siblings('input.select-dropdown').on('mousedown', onMouseDown);
  });

@chi-bd
Copy link

chi-bd commented Dec 23, 2015

My PR was rejected because of the following reason.

but introduces another because now the select no longer closes when you normally click on an item.

Such problem doesn't occur on my environment.
When I click on an item normally, the selectbox is closed automatically, that is a correct operation.
I tested InternetExplorer 11.0.9600.17937 and Chrome 47.0.2526.73m on Windows8.1 and Windows7.

Could anyone help me to test this additionally?

@blinchi
Copy link

blinchi commented Feb 8, 2016

Hi chi-bd, I test your solution

$(document).ready(function() {
$('select').material_select();

  • var onMouseDown = function(e) {
  •  // preventing the default still allows the scroll, but blocks the blur.
    
  •  // We're inside the scrollbar if the clientX is >= the clientWidth.
    
  •  if (e.clientX >= e.target.clientWidth || e.clientY >= e.target.clientHeight) {
    
  •    e.preventDefault();
    
  •  }
    
  • };
  • //$newSelect.on('mousedown', onMouseDown);
  • $(’select').siblings('input.select-dropdown').on('mousedown', onMouseDown);
    });

and not work for me on IE 10, because after select an item select not close automatically. Without your solution after you select an item the select close auto.
Sorry for my english.

@chi-bd
Copy link

chi-bd commented Feb 11, 2016

Dear blinchi, thanks for testing.

not work for me on IE 10, because after select an item select not close automatically.

I can't reproduce it for lack of IE10 environment, but I probably found a way to close forcibly.
Please test the following workaround, additionally.

- $('select').material_select();
+ $('select').material_select(function() {
+     $('input.select-dropdown').trigger('close');
+ });

material_select() can be received the callback function as an argument, and it calls when the item has selected.
so, executing "trigger('close')" in the callback cause to close forcibly, I think.

@sly7-7
Copy link

sly7-7 commented Feb 18, 2016

We have the same issue, but only on IE (at least 10 & 11).

@chi-bd Thanks for the workarounds, combining both seems to works as expected.

$(document).ready(function() {
    $('select').material_select(function() {
     $('input.select-dropdown').trigger('close');
   });

    var onMouseDown = function(e) {
      // preventing the default still allows the scroll, but blocks the blur.
      // We're inside the scrollbar if the clientX is >= the clientWidth.
      if (e.clientX >= e.target.clientWidth || e.clientY >= e.target.clientHeight) {
        e.preventDefault();
      }
    };
    $(’select').siblings('input.select-dropdown').on('mousedown', onMouseDown);
  }); 

@blinchi
Copy link

blinchi commented Mar 15, 2016

@sly7-7 ouhhh yeahhh your code Works perfect!

@jpt007
Copy link

jpt007 commented Jan 18, 2017

@sly7-7 - Looks like if you have more than one select list vertically, opening the drop down below and then opening the one above causes layering issues with both dropdowns. Didn't know if you experienced this issue and potential workarounds.

update:
I added a trigger to close any other select lists that are not the originator of the mouse down event and initial tests appear to have worked. Code for onMouseDown:

var onMouseDown = function(e) {
    // added to trigger all other select lists to close
    $("input[data-activates!='" + $(this).attr('data-activates') + "'].select-dropdown").trigger('close');
                
    // preventing the default still allows the scroll, but blocks the blur.
    // We're inside the scrollbar if the clientX is >= the clientWidth.
    if (e.clientX >= e.target.clientWidth || e.clientY >= e.target.clientHeight) {
         e.preventDefault();
    }
};

@kpingel
Copy link

kpingel commented Jan 20, 2017

@sly7-7 -- Your fix worked, but makes it so that you can no longer begin typing to jump to a specific dropdown option. :( Thoughts?

@maiconsansonrc
Copy link

On mobile does not work at all! Any thoughts?

@Kiel-H-Byrne
Copy link

I have a dropdown that dissapears when clicked on mobile as well..
i 'tap' and hold in order to scroll down the dropdown, the tap-n-hold is registered as a click, but the list item (href) isn't navigated to either...
like i have to tap it suuuuper light in order to get to the link item in the dropdown.
no scrolling works on mobile, because the tap is registered as some type of click, and dropdown dissapears before i release the tap.

@acburst
Copy link
Collaborator

acburst commented Feb 27, 2017

This was fixed in 1d94110

@acburst acburst closed this as completed Feb 27, 2017
@jaylegere
Copy link

After upgrading to 0.98.1, I am still seeing this issue in IE 11 (11.0.9600.18617) on Windows 7. It works fine in Chrome (57.0.2987.110).

@kevzlou7979
Copy link

Hi there,

I found a workaround for mobile devices.
We used Materialize on Java Web Application also know as GWT
Check it out : http://gwtmaterialdesign.github.io/gwt-material-demo/

var onMouseDown = function(e) {
    // added to trigger all other select lists to close
    $("input[data-activates!='" + $(this).attr('data-activates') + "'].select-dropdown").trigger('close');
                
    // preventing the default still allows the scroll, but blocks the blur.
    // We're inside the scrollbar if the clientX is >= the clientWidth.
    if (e.clientX >= e.target.clientWidth || e.clientY >= e.target.clientHeight) {
        // Apply only on non-touch screen devices.
        if('ontouchstart' in document.documentElement) {
              e.preventDefault();
        }
    }
};

@Kiel-H-Byrne
Copy link

Kiel-H-Byrne commented Apr 20, 2017 via email

@kevzlou7979
Copy link

@tdotholla Yeah both Scroll wheel and cursor is working fine

@RenaldasK
Copy link

The issue is still present in IE11. I'm using v0.98.0

@pdlk
Copy link

pdlk commented Jul 24, 2017

Version 0.100.1, issue remains (IE10, IE11)

@cpalmerbright
Copy link

Is there any chance of a solution for this? Still a problem in IE11

@Fasani
Copy link

Fasani commented Sep 7, 2017

@cpalmerbright I also have this problem in IE11, did you find a fix?

@Fasani
Copy link

Fasani commented Sep 8, 2017

It would appear that IE fire's a blur event that other browsers do not fire on click of the scroll bar.

Search for this function:
$.fn.material_select = function(callback) {

Notice this line:
$newSelect.on("blur", function() {

This is the event that is closing the drop-down in IE.

We fixed this behaviour using this code:
$newSelect.on("blur", function() {
var that = this;

$(this).find(' ~ .dropdown-content span').off('click');
$(this).find(' ~ .dropdown-content span').on('click', function() {
$(that).trigger('close');
});

var containers = $(".select-dropdown");
if (!multiple && !containers.is(e.target)) {
$(this).trigger("close");
}

options.find("li.selected").removeClass("selected");
});

This needs further testing I guess to ensure that it doesn't have any unwanted side effects but initially, this seems to fix the issue.

@Dogfalo
Copy link
Owner

Dogfalo commented Sep 8, 2017

We have a fix coming for this in v1 with a reworked select that does not rely on focus

@ijabit
Copy link

ijabit commented Sep 27, 2017

Any ETA on V1?

@worthy7
Copy link

worthy7 commented Oct 18, 2017

@Fasani unfortunately ugly solution, but it's better than nothing. Anyone got any news on this?
I have just encountered this in our system (lots of IE11 users) whilst using Typeahead.js

@brahmaui
Copy link

brahmaui commented Mar 6, 2018

@sly7-7 It is not working in Safari.
I have used PHP Laravel can anyone help me.

this is the code

<div class="input-field">
                                    <select id="category" name="category" class="validate">
                                        <option value="" disabled> Select Category </option>
                                        
                                        <option value="1">1</option>
                                        <option value="2">2</option>
                                        <option value="3">3</option>
                                        <option value="4">4</option>
                                        <option value="5">5</option>
                                    </select>
                                    <label for="category">Cause Categories</label>
                                </div>
<script>
$(document).ready(function() {
    $('select').material_select(function() {
     $('input.select-dropdown').trigger('close');
   });

    var onMouseDown = function(e) {
      if (e.clientX >= e.target.clientWidth || e.clientY >= e.target.clientHeight) {
        e.preventDefault();
      }
    };
    $(’select').siblings('input.select-dropdown').on('mousedown', onMouseDown);
  }); 
</script>

@frostless
Copy link

Many above methods work, but if we do e.preventDefault(); then we lose the browser typing context ability. I mean if you type a letter, the select wont go to the item anymore, any workaround with this?

@hari457627
Copy link

Hi i'm using Downshift material ui component.
scroll bar up and down arrows with mouse clicks is working fine in normal pages,
but its not working in material ui modals.
in modal, when i'm clicking in Downshift suggestions scroll up and right arrow with mouse, then suggestions popup is closing.
Can anybody help me to solve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests