Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit b3177f2

Browse files
author
Robert Messerle
committed
fix(select): fixes positioning of select menu and sets it to append to the body again
Closes #6044
1 parent 503fa9d commit b3177f2

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

docs/config/template/index.template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ <h2 class="menu-heading md-subhead" ng-if="section.type === 'heading'" id="headi
5656
<div layout="column" tabIndex="-1" role="main" flex>
5757
<md-toolbar class="md-whiteframe-glow-z1 site-content-toolbar">
5858

59-
<div class="md-toolbar-tools docs-toolbar-tools" ng-click="openMenu()" tabIndex="-1">
60-
<md-button class="md-icon-button" hide-gt-sm aria-label="Toggle Menu">
59+
<div class="md-toolbar-tools docs-toolbar-tools" tabIndex="-1">
60+
<md-button class="md-icon-button" ng-click="openMenu()" hide-gt-sm aria-label="Toggle Menu">
6161
<md-icon md-svg-src="img/icons/ic_menu_24px.svg"></md-icon>
6262
</md-button>
6363
<div layout="row" flex class="fill-height">

src/components/select/select.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
452452
element: selectContainer,
453453
target: element[0],
454454
preserveElement: true,
455-
parent: element,
456455
hasBackdrop: true,
457456
loadingAsync: attr.mdOnOpen ? scope.$eval(attr.mdOnOpen) || true : false
458457
}).finally(function() {
@@ -1239,7 +1238,7 @@ function SelectProvider($$interimElementProvider) {
12391238
* trigger the [optional] user-defined expression
12401239
*/
12411240
function announceClosed(opts) {
1242-
var mdSelect = opts.selectEl.controller('mdSelect');
1241+
var mdSelect = opts.target.controller('mdSelect');
12431242
if (mdSelect) {
12441243
var menuController = opts.selectEl.controller('mdSelectMenu');
12451244
mdSelect.setLabelText(menuController.selectedLabels());
@@ -1254,7 +1253,7 @@ function SelectProvider($$interimElementProvider) {
12541253
function calculateMenuPositions(scope, element, opts) {
12551254
var
12561255
containerNode = element[0],
1257-
targetNode = opts.target[0].children[1], // target the label
1256+
targetNode = opts.target[0].children[0], // target the label
12581257
parentNode = $document[0].body,
12591258
selectNode = opts.selectEl[0],
12601259
contentNode = opts.contentEl[0],

src/components/select/select.spec.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
describe('<md-select>', function() {
2-
var attachedElements = [];
2+
var attachedElements = [],
3+
body;
34

45
beforeEach(module('material.components.input'));
56
beforeEach(module('material.components.select'));
67

8+
beforeEach(inject(function($document) {
9+
body = $document[0].body;
10+
}));
11+
12+
afterEach(inject(function ($document) {
13+
var body = $document[0].body;
14+
var children = body.querySelectorAll('.md-select-menu-container');
15+
for (var i = 0; i < children.length; i++) {
16+
angular.element(children[i]).remove();
17+
}
18+
}));
19+
720
afterEach(inject(function($document) {
821
attachedElements.forEach(function(element) {
922
element.remove();
@@ -39,7 +52,7 @@ describe('<md-select>', function() {
3952
var select = setupSelect('ng-model="val", md-container-class="test"').find('md-select');
4053
openSelect(select);
4154

42-
var container = select[0].querySelector('.md-select-menu-container');
55+
var container = body.querySelector('.md-select-menu-container');
4356
expect(container).toBeTruthy();
4457
expect(container.classList.contains('test')).toBe(true);
4558
}));
@@ -720,7 +733,7 @@ describe('<md-select>', function() {
720733
openSelect(el);
721734
expect(el.attr('aria-expanded')).toBe('true');
722735

723-
var selectMenu = el.find('md-select-menu');
736+
var selectMenu = $document.find('md-select-menu');
724737
pressKey(selectMenu, 27);
725738
waitForSelectClose();
726739

@@ -793,7 +806,7 @@ describe('<md-select>', function() {
793806
var el = setupSelect('ng-model="someVal"', [1, 2, 3]).find('md-select');
794807
openSelect(el);
795808
expectSelectOpen(el);
796-
var selectMenu = angular.element(el.find('md-select-menu'));
809+
var selectMenu = $document.find('md-select-menu');
797810
expect(selectMenu.length).toBe(1);
798811
pressKey(selectMenu, 27);
799812
waitForSelectClose();
@@ -906,8 +919,8 @@ describe('<md-select>', function() {
906919
function clickOption(select, index) {
907920
inject(function($rootScope, $document) {
908921
expectSelectOpen(select);
909-
var openMenu = select.find('md-select-menu');
910-
var opt = angular.element(select.find('md-option')[index]).find('div')[0];
922+
var openMenu = $document.find('md-select-menu');
923+
var opt = angular.element(openMenu.find('md-option')[index]).find('div')[0];
911924

912925
if (!opt) throw Error('Could not find option at index: ' + index);
913926
var target = angular.element(opt);
@@ -925,14 +938,16 @@ describe('<md-select>', function() {
925938

926939
function expectSelectClosed(element) {
927940
element = angular.element(element);
928-
var menu = angular.element(element[0].querySelector('.md-select-menu-container'));
929-
expect(menu.hasClass('md-active')).toBe(false);
930-
expect(menu.attr('aria-hidden')).toBe('true');
941+
var menu = angular.element(body.querySelector('.md-select-menu-container'));
942+
if (menu.length) {
943+
expect(menu.hasClass('md-active')).toBe(false);
944+
expect(menu.attr('aria-hidden')).toBe('true');
945+
}
931946
}
932947

933948
function expectSelectOpen(element) {
934949
element = angular.element(element);
935-
var menu = angular.element(element[0].querySelector('.md-select-menu-container'));
950+
var menu = angular.element(body.querySelector('.md-select-menu-container'));
936951
expect(menu.hasClass('md-active')).toBe(true);
937952
expect(menu.attr('aria-hidden')).toBe('false');
938953
}

0 commit comments

Comments
 (0)