Skip to content

Force showing dropdown-container always above or below #3121

Closed

Description

@ifthenelse

As far as I know, there's no option which cover this.
Since it can't be just achieved via css customization, the only way is to intercept the opening of the select and the reposition the dropdown-container manually, but It's definitely not the best solution.
Any chance to see it in the upcoming v4.x?

Activity

  1. mh-nichts commented on May 13, 2015

    @mh-nichts

    I would also be interested by this feature !

  2. leonardomdr commented on Aug 21, 2015

    @leonardomdr

    I did this in Select2 3.5.2 to force the container to start above instead of below the search box.

    In select2.js you search for "positionDropdown: function() {" and change to "positionDropdown: function(forceAbove) {"

    In the same function, after the var settings, paste this code:

    forceAbove = typeof forceAbove !== 'undefined' ? forceAbove : false;
    if (forceAbove) {
        enoughRoomAbove = true;
        enoughRoomBelow = false;
    }

    After that, to force your select2 to show above, use this

    .on("select2-open", function() { 
        $(this).select2('positionDropdown', true);
    });
  3. apaulo commented on Dec 31, 2015

    @apaulo

    There is a simpler way to implement a "forceabove" param:

    1. In select2.js search for "positionDropdown: function()";

    2. at the var settings change
      aboveNow = $dropdown.hasClass("select2-drop-above")
      to
      aboveNow = this.opts.forceabove || $dropdown.hasClass("select2-drop-above")

    3. Now you can setup select2 with option
      forceabove = true

  4. ganholete commented on Jan 8, 2016

    @ganholete

    Same question

  5. tirdadc commented on Jan 27, 2016

    @tirdadc

    I was considering switching from Chosen to Select2, but I was surprised to see that this was something you couldn't control, and worse, it would be inconsistent: depending on the contents of the dropdown, it alternates between above and below.

  6. added a commit that references this issue on Aug 31, 2016
  7. added a commit that references this issue on Oct 6, 2016
    feb69c0
  8. added a commit that references this issue on Jul 7, 2018
    9992e27
  9. stale commented on Mar 13, 2019

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  10. stale commented on May 18, 2019

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  11. hassanrazmy commented on Jan 18, 2021

    @hassanrazmy

    It looks like making the bottom value auto forcefully in CSS can also do the trick. I used the following code and it is kind of working for me fine.
    .my_select_picker_trigger.dropup .dropdown-menu { bottom: auto !important; }

  12. aurovrata commented on Sep 13, 2021

    @aurovrata

    following @apaulo solution...

    There is a simpler way to implement a "forceabove" param:

    1. In select2.js search for "positionDropdown: function()";
    
    2. at the var settings change
       `aboveNow = $dropdown.hasClass("select2-drop-above")`
       to
       `aboveNow = this.opts.forceabove || $dropdown.hasClass("select2-drop-above")`
    
    3. Now you can setup select2 with option
       `forceabove = true`
    

    in the latest version, you want to use

    this.options.get('forceabove')

  13. mehulvardiya commented on Sep 7, 2024

    @mehulvardiya
    dropdown my site proper working but 2-3days Iface issue that is select2 dropdown I want open dropdown below or above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions