Skip to content

feat(autocomplete): align with 2018 material design spec #12570

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
Aug 17, 2018
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
10 changes: 10 additions & 0 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,16 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
{originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom'}
]);

// The overlay edge connected to the trigger should have squared corners, while
// the opposite end has rounded corners. We apply a CSS class to swap the
// border-radius based on the overlay position.
this._positionStrategy.positionChanges.subscribe(({connectionPair}) => {
if (this.autocomplete) {
this.autocomplete._classList['mat-autocomplete-panel-above'] =
connectionPair.originY === 'top';
}
});

return this._positionStrategy;
}

Expand Down
14 changes: 11 additions & 3 deletions src/lib/autocomplete/autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@

/**
* The max-height of the panel, currently matching mat-select value.
* TODO: Check value with MD team.
*/
$mat-autocomplete-panel-max-height: 256px !default;
$mat-autocomplete-panel-border-radius: 4px !default;

.mat-autocomplete-panel {
@include mat-menu-base(8);
visibility: hidden;
@include mat-menu-base(4);

visibility: hidden;
max-width: none;
max-height: $mat-autocomplete-panel-max-height;
position: relative;
width: 100%;
border-bottom-left-radius: $mat-autocomplete-panel-border-radius;
border-bottom-right-radius: $mat-autocomplete-panel-border-radius;

&.mat-autocomplete-visible {
visibility: visible;
Expand All @@ -28,3 +30,9 @@ $mat-autocomplete-panel-max-height: 256px !default;
outline: solid 1px;
}
}

.mat-autocomplete-panel-above {
border-radius: 0;
border-top-left-radius: $mat-autocomplete-panel-border-radius;
border-top-right-radius: $mat-autocomplete-panel-border-radius;
}
6 changes: 6 additions & 0 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,13 +1377,15 @@ describe('MatAutocomplete', () => {
fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
zone.simulateZoneExit();
fixture.detectChanges();

const inputBottom = inputReference.getBoundingClientRect().bottom;
const panel = overlayContainerElement.querySelector('.mat-autocomplete-panel')!;
const panelTop = panel.getBoundingClientRect().top;

expect(Math.floor(inputBottom))
.toEqual(Math.floor(panelTop), `Expected panel top to match input bottom by default.`);
expect(panel.classList).not.toContain('mat-autocomplete-panel-above');
}));

it('should reposition the panel on scroll', () => {
Expand Down Expand Up @@ -1430,13 +1432,17 @@ describe('MatAutocomplete', () => {
fixture.componentInstance.trigger.openPanel();
fixture.detectChanges();
zone.simulateZoneExit();
fixture.detectChanges();

const inputTop = inputReference.getBoundingClientRect().top;
const panel = overlayContainerElement.querySelector('.cdk-overlay-pane')!;
const panelBottom = panel.getBoundingClientRect().bottom;

expect(Math.floor(inputTop))
.toEqual(Math.floor(panelBottom), `Expected panel to fall back to above position.`);

expect(panel.querySelector('.mat-autocomplete-panel')!.classList)
.toContain('mat-autocomplete-panel-above');
}));

it('should allow the panel to expand when the number of results increases', fakeAsync(() => {
Expand Down