Skip to content

fix(select): align first option to trigger when it is inside a group #5153

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

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,19 @@ describe('MdSelect', () => {
expect(Math.floor(selectedOptionLeft)).toEqual(Math.floor(triggerLeft - 16));
}));

it('should align the first option to the trigger, if nothing is selected', fakeAsync(() => {
trigger.click();
groupFixture.detectChanges();

const triggerTop = trigger.getBoundingClientRect().top;
const optionTop = overlayContainerElement.querySelector('.cdk-overlay-pane md-option')
.getBoundingClientRect().top;

// Since the option is 18px higher than the trigger, it needs to be adjusted by 9px.
expect(Math.floor(optionTop))
.toBe(Math.floor(triggerTop - 9), 'Expected trigger to align with the first option.');
}));

});

});
Expand Down
5 changes: 3 additions & 2 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
// we must only adjust for the height difference between the option element
// and the trigger element, then multiply it by -1 to ensure the panel moves
// in the correct direction up the page.
this._offsetY = (SELECT_ITEM_HEIGHT - SELECT_TRIGGER_HEIGHT) / 2 * -1;
this._offsetY = (SELECT_ITEM_HEIGHT - SELECT_TRIGGER_HEIGHT) / 2 * -1 -
(this._getLabelCountBeforeOption(0) * SELECT_ITEM_HEIGHT);
}

this._checkOverlayWithinViewport(maxScroll);
Expand Down Expand Up @@ -874,7 +875,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
if (this.multiple) {
offsetX = SELECT_MULTIPLE_PANEL_PADDING_X;
} else {
let selected = this._selectionModel.selected[0];
let selected = this._selectionModel.selected[0] || this.options.first;
offsetX = selected && selected.group ? SELECT_PANEL_INDENT_PADDING_X : SELECT_PANEL_PADDING_X;
}

Expand Down