Skip to content

Commit a82ffe8

Browse files
committed
feat(autocomplete): align with 2018 material design
Aligns the autocomplete with the most-recent Material design spec. These changes are based on the menu designs since there isn't any concrete design for an autocomplete. Note that the changes only cover the adjustments to the autocomplete panel. The design changes for the options will come together with `mat-select` since the two components both use `mat-option`.
1 parent 1e1751f commit a82ffe8

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,16 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
579579
{originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom'}
580580
]);
581581

582+
// The overlay edge connected to the trigger should have squared corners, while
583+
// the opposite end has rounded corners. We apply a CSS class to swap the
584+
// border-radius based on the overlay position.
585+
this._positionStrategy.positionChanges.subscribe(({connectionPair}) => {
586+
if (this.autocomplete) {
587+
this.autocomplete._classList['mat-autocomplete-panel-above'] =
588+
connectionPair.originY === 'top';
589+
}
590+
});
591+
582592
return this._positionStrategy;
583593
}
584594

src/lib/autocomplete/autocomplete.scss

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

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

1010
.mat-autocomplete-panel {
11-
@include mat-menu-base(8);
12-
visibility: hidden;
11+
@include mat-menu-base(4);
1312

13+
visibility: hidden;
1414
max-width: none;
1515
max-height: $mat-autocomplete-panel-max-height;
1616
position: relative;
1717
width: 100%;
18+
border-bottom-left-radius: $mat-autocomplete-panel-border-radius;
19+
border-bottom-right-radius: $mat-autocomplete-panel-border-radius;
1820

1921
&.mat-autocomplete-visible {
2022
visibility: visible;
@@ -28,3 +30,9 @@ $mat-autocomplete-panel-max-height: 256px !default;
2830
outline: solid 1px;
2931
}
3032
}
33+
34+
.mat-autocomplete-panel-above {
35+
border-radius: 0;
36+
border-top-left-radius: $mat-autocomplete-panel-border-radius;
37+
border-top-right-radius: $mat-autocomplete-panel-border-radius;
38+
}

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,13 +1377,15 @@ describe('MatAutocomplete', () => {
13771377
fixture.componentInstance.trigger.openPanel();
13781378
fixture.detectChanges();
13791379
zone.simulateZoneExit();
1380+
fixture.detectChanges();
13801381

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

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

13891391
it('should reposition the panel on scroll', () => {
@@ -1430,13 +1432,17 @@ describe('MatAutocomplete', () => {
14301432
fixture.componentInstance.trigger.openPanel();
14311433
fixture.detectChanges();
14321434
zone.simulateZoneExit();
1435+
fixture.detectChanges();
14331436

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

14381441
expect(Math.floor(inputTop))
14391442
.toEqual(Math.floor(panelBottom), `Expected panel to fall back to above position.`);
1443+
1444+
expect(panel.querySelector('.mat-autocomplete-panel')!.classList)
1445+
.toContain('mat-autocomplete-panel-above');
14401446
}));
14411447

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

0 commit comments

Comments
 (0)