material icon indicating copy to clipboard operation
material copied to clipboard

select: md-select-menu positioned above control when options are async

Open fridolin-koch opened this issue 11 years ago • 35 comments

I'm using the async variant of md-select. Instead of the menu appearing directly over the md-select it appears a few pixels above. The bug only occurs if it contains only a few elements.

screen shot 2015-10-29 at 18 37 00

This bug seems to be related to my layout, am I using the containers wrong or is this a bug?

I've created a codepen http://codepen.io/anon/pen/VvdZYx

fridolin-koch avatar Oct 29 '15 17:10 fridolin-koch

Did you tried it outside of code pen? If we change the body element in your example to div it's working If you didn't tried it outside please check, i'm sure it's working.

EladBezalel avatar Oct 30 '15 11:10 EladBezalel

Yep, the issue comes from the app I'm currently developing. I tried to replicate the problem inside Codepen to make the issue more feasible.

The actual code looks like that:

<body layout="column">
  <stm-navbar></stm-navbar>
  <div layout="row" flex>
    <!-- Sidebar -->
    <stm-sidenav layout="column"></stm-sidenav>
    <!-- Content container -->
    <div layout="column" class="ui-view-container" flex style="overflow: auto">
      <md-progress-linear ng-show="$appLoading" md-mode="indeterminate"></md-progress-linear>
      <stm-breadcrumbs></stm-breadcrumbs>
      <div ui-view></div>
    </div>
  </div>
</body>

fridolin-koch avatar Nov 01 '15 17:11 fridolin-koch

It seems like the issue is not related to a certain layout or browser:

Chrome:

chrome_1 chrome_2

Firefox:

firefox_1 firefox_2

Here is the example code used: https://gist.github.com/fridolin-koch/2c9fc5b24a5f558a9ca1

fridolin-koch avatar Nov 04 '15 08:11 fridolin-koch

It's odd, I had a look on this but nothing formal yet, I'm on it.

EladBezalel avatar Nov 04 '15 12:11 EladBezalel

@EladBezalel assigning to you only because you claimed it. Feel free to kick it back to me if you're no longer investigating

rschmukler avatar Nov 12 '15 00:11 rschmukler

I have this issue too . @fridolin-koch like you say it only happen when have few of options in my case is two . I use md-select in my md-tabs .

sample image
screen shot 2558-11-13 at 1 50 00 pm

but if i have more options it will render collectly screen shot 2558-11-13 at 1 55 53 pm

chayutzee avatar Nov 13 '15 06:11 chayutzee

Similar problem here... The options are just floating on top of the page, no matter where the md-select is, no matter how many options, no matter whether async or not... (rc3)

jschlieber avatar Nov 15 '15 17:11 jschlieber

@rschmukler can you take a look at this also?

EladBezalel avatar Nov 15 '15 18:11 EladBezalel

I'm having trouble recreating this issue. Using the code from @fridolin-koch I made this demo which appears to be working. Can you guys try on master and confirm that this issue still exists? If it does, can someone please supply me with a demo that I can work from

rschmukler avatar Nov 20 '15 20:11 rschmukler

@rschmukler when upgrading your codepen to angular 1.4.7 (which is what he's using in his demo) it's seems to be broken..

EladBezalel avatar Nov 21 '15 10:11 EladBezalel

The behaviour slightly changed in v1.0.0-rc5 using angular.js 1.4.8. Notice the options are less detached from the control.

v1.0.0-rc5: http://codepen.io/fridolin-koch/pen/QjXOxg v1.0.0-rc4-master-5e5e6cd: http://codepen.io/fridolin-koch/pen/dYBZKB

fridolin-koch avatar Nov 26 '15 16:11 fridolin-koch

this or some variation of it occurs on the doc site. in Demo of Basic Address select of State the first selection positions the options correctly subsequent attempts at selection position the options at various vertical positions relative to top of something depending on how far down the option list is currently selected.

if the md-select element is lower on the page, the behavior is even more bizarre

FWIW, in trying to research the code, I discovered that a horizontal resize causes the option list to be placed where intended.

jlmagee avatar Dec 08 '15 02:12 jlmagee

in function calculateMenuPositions(scope, element, opts) { this calculation transformOrigin = (centeredRect.left + targetRect.width / 2) + 'px ' + (centeredRect.top + centeredRect.height / 2 - contentNode.scrollTop) + 'px 0px';

uses contentNode.scrollTop which is always zero when selecting (re-opening) the select menu after it has been populated because contentNode is a hidden element appended at the bottom of the body

I haven't figured out what the calculations are trying to do but there is some never dead code in this function which doesn't make it easier.

jlmagee avatar Dec 08 '15 17:12 jlmagee

@rschmukler @jelbourn Well, other code considerations aside, the issue seems to be that isScrollable is not set properly. I moved it and the other line to immediately after all the initial variable settings, as follows

  // give the container some shape befor depending on it
  containerNode.style.display = 'block';
  var isScrollable = contentNode.scrollHeight > contentNode.offsetHeight;

Seems to work as expected now. I'll continue testing in various window sizes and let you know if I find anything else.

jlmagee avatar Dec 09 '15 15:12 jlmagee

I confirm with 1.0.0 I am getting the same issue (codepen with Scooby Doo above) in my app.

Recap:

  • with an horizontal resize causes the option list to be placed where intended
  • setting ng-selected="$index == 0" the option list is ok

Any workaround?

(my md-select snippet seems quite standard, I hope)

        <md-input-container>
            <md-select ng-model="vm.selectedGranularity" aria-label="Granularity"
                ng-change="vm.changeChart(vm.selectedInstrument, vm.selectedGranularity)">
                <md-option ng-value="granularity"
                    ng-selected="granularity == vm.selectedGranularity || $index == 0"
                    ng-repeat="granularity in vm.granularities">
                    {{ granularity }}
                </md-option>
            </md-select>
        </md-input-container>

albertosantini avatar Dec 16 '15 22:12 albertosantini

In Material 1.0.1, my use case is fixed. Thanks!

albertosantini avatar Dec 19 '15 11:12 albertosantini

I'cant confirm this, in 1.0.1 the behaviour is still different from "regular" selects:

http://codepen.io/fridolin-koch/pen/ZQOpXN

untitled

fridolin-koch avatar Dec 21 '15 11:12 fridolin-koch

I'm also having this issue, and only on async selects that already have a selected option. I'm using v1.0.4

timmyrosen avatar Feb 02 '16 23:02 timmyrosen

+1

ismarslomic avatar Feb 14 '16 07:02 ismarslomic

+1

Michsior14 avatar Feb 20 '16 13:02 Michsior14