Skip to content

Commit

Permalink
fix(material-experimental/mdc-progress-bar): account for breaking cha…
Browse files Browse the repository at this point in the history
…nges in latest canary

Updates the repo to the latest MDC canary version and accounts for the breaking changes introduced in material-components/material-components-web@98b8434.
  • Loading branch information
crisbeto authored and mmalerba committed Mar 6, 2020
1 parent e441a8c commit 5d49f37
Show file tree
Hide file tree
Showing 5 changed files with 536 additions and 528 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@types/youtube": "^0.0.38",
"@webcomponents/custom-elements": "^1.1.0",
"core-js": "^2.6.9",
"material-components-web": "^6.0.0-canary.265ecbad5.0",
"material-components-web": "6.0.0-canary.17b9699c4.0",
"rxjs": "^6.5.3",
"systemjs": "0.19.43",
"tslib": "^1.10.0",
Expand Down
6 changes: 4 additions & 2 deletions src/material-experimental/mdc-progress-bar/progress-bar.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="mdc-linear-progress">
<div class="mdc-linear-progress__buffering-dots"></div>
<div class="mdc-linear-progress__buffer"></div>
<div class="mdc-linear-progress__buffer">
<div class="mdc-linear-progress__buffer-bar"></div>
<div class="mdc-linear-progress__buffer-dots"></div>
</div>
<div class="mdc-linear-progress__bar mdc-linear-progress__primary-bar">
<span class="mdc-linear-progress__bar-inner"></span>
</div>
Expand Down
16 changes: 10 additions & 6 deletions src/material-experimental/mdc-progress-bar/progress-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,32 @@ describe('MDC-based MatProgressBar', () => {
const primaryStyles =
progressElement.nativeElement.querySelector('.mdc-linear-progress__primary-bar').style;
const bufferStyles =
progressElement.nativeElement.querySelector('.mdc-linear-progress__buffer').style;
progressElement.nativeElement.querySelector('.mdc-linear-progress__buffer-bar').style;

// Parse out and round the value since different
// browsers return the value with a different precision.
const getBufferValue = () => Math.floor(parseInt(bufferStyles.flexBasis));

expect(primaryStyles.transform).toBe('scaleX(0)');
expect(bufferStyles.transform).toBe('scaleX(1)');
expect(getBufferValue()).toBe(100);

progressComponent.value = 40;
expect(primaryStyles.transform).toBe('scaleX(0.4)');
expect(bufferStyles.transform).toBe('scaleX(1)');
expect(getBufferValue()).toBe(100);

progressComponent.value = 35;
progressComponent.bufferValue = 55;
expect(primaryStyles.transform).toBe('scaleX(0.35)');
expect(bufferStyles.transform).toBe('scaleX(1)');
expect(getBufferValue()).toBe(100);

progressComponent.mode = 'buffer';
expect(primaryStyles.transform).toBe('scaleX(0.35)');
expect(bufferStyles.transform).toEqual('scaleX(0.55)');
expect(getBufferValue()).toEqual(55);

progressComponent.value = 60;
progressComponent.bufferValue = 60;
expect(primaryStyles.transform).toBe('scaleX(0.6)');
expect(bufferStyles.transform).toEqual('scaleX(0.6)');
expect(getBufferValue()).toEqual(60);
});

it('should remove the `aria-valuenow` attribute in indeterminate mode', () => {
Expand Down
11 changes: 6 additions & 5 deletions src/material-experimental/mdc-progress-bar/progress-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
/** Adapter used by MDC to interact with the DOM. */
private _adapter: MDCLinearProgressAdapter = {
addClass: (className: string) => this._rootElement.classList.add(className),
getBuffer: () => this._bufferBar,
getPrimaryBar: () => this._primaryBar,
forceLayout: () => this._platform.isBrowser && this._rootElement.offsetWidth,
removeAttribute: (name: string) => this._rootElement.removeAttribute(name),
setAttribute: (name: string, value: string) => this._rootElement.setAttribute(name, value),
hasClass: (className: string) => this._rootElement.classList.contains(className),
removeClass: (className: string) => this._rootElement.classList.remove(className),
setStyle: (el: HTMLElement, styleProperty: string, value: string) => {
(el.style as any)[styleProperty] = value;
setPrimaryBarStyle: (styleProperty: string, value: string) => {
(this._primaryBar.style as any)[styleProperty] = value;
},
setBufferBarStyle: (styleProperty: string, value: string) => {
(this._bufferBar.style as any)[styleProperty] = value;
}
};

Expand Down Expand Up @@ -151,7 +152,7 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie

this._rootElement = element.querySelector('.mdc-linear-progress') as HTMLElement;
this._primaryBar = element.querySelector('.mdc-linear-progress__primary-bar') as HTMLElement;
this._bufferBar = element.querySelector('.mdc-linear-progress__buffer') as HTMLElement;
this._bufferBar = element.querySelector('.mdc-linear-progress__buffer-bar') as HTMLElement;

this._foundation = new MDCLinearProgressFoundation(this._adapter);
this._foundation.init();
Expand Down
Loading

0 comments on commit 5d49f37

Please sign in to comment.