Skip to content

Commit

Permalink
fix(chips): ClientRect/DOMRect is not IE11 compatible (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpboyd authored and Matt Goo committed May 30, 2019
1 parent ac7e184 commit 88697da
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
30 changes: 28 additions & 2 deletions packages/chips/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,38 @@ export class Chip extends React.Component<ChipProps, ChipState> {
.getPropertyValue(propertyName);
},
getRootBoundingClientRect: () => {
if (!this.chipElement) return new ClientRect();
if (!this.chipElement) {
// new DOMRect is not IE11 compatible
const defaultDOMRect = {
bottom: 0,
height: 0,
left: 0,
right: 0,
top: 0,
width: 0,
x: 0,
y: 0,
};
return defaultDOMRect;
}
return this.chipElement.getBoundingClientRect();
},
getCheckmarkBoundingClientRect: () => {
const {chipCheckmark} = this.props;
if (!chipCheckmark) return new ClientRect();
if (!(chipCheckmark && chipCheckmark.props && chipCheckmark.props.getBoundingClientRect)) {
// new DOMRect is not IE11 compatible
const defaultDOMRect = {
bottom: 0,
height: 0,
left: 0,
right: 0,
top: 0,
width: 0,
x: 0,
y: 0,
};
return defaultDOMRect;
}
return chipCheckmark.props.getBoundingClientRect();
},
setStyleProperty: (propertyName: keyof React.CSSProperties, value: string | null) => {
Expand Down
15 changes: 14 additions & 1 deletion packages/tab-indicator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,20 @@ export default class TabIndicator extends React.Component<TabIndicatorProps, {}>

computeContentClientRect = () => {
const contentElement = this.getNativeContentElement();
if (!(contentElement && contentElement.getBoundingClientRect)) return new ClientRect();
if (!(contentElement && contentElement.getBoundingClientRect)) {
// new DOMRect is not IE11 compatible
const defaultDOMRect = {
bottom: 0,
height: 0,
left: 0,
right: 0,
top: 0,
width: 0,
x: 0,
y: 0,
};
return defaultDOMRect;
}
return contentElement.getBoundingClientRect();
};

Expand Down
32 changes: 24 additions & 8 deletions packages/tab-scroller/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,35 @@ export default class TabScroller extends React.Component<
getScrollContentOffsetWidth: this.getScrollContentWidth,
getScrollAreaOffsetWidth: () =>
this.areaElement.current ? this.areaElement.current.offsetWidth : 0,
computeScrollAreaClientRect: () =>
this.areaElement.current ?
this.areaElement.current.getBoundingClientRect() :
new ClientRect(),
computeScrollContentClientRect: () =>
this.contentElement.current ?
this.contentElement.current.getBoundingClientRect() :
new ClientRect(),
computeScrollAreaClientRect: () => {
return this.getBoundingClientRectOf(this.contentElement.current);
},
computeScrollContentClientRect: () => {
return this.getBoundingClientRectOf(this.contentElement.current);
},
computeHorizontalScrollbarHeight: () =>
computeHorizontalScrollbarHeight(document),
};
}

getBoundingClientRectOf = (element: HTMLElement | null) => {
if (!element) {
// new DOMRect is not IE11 compatible
const defaultDOMRect = {
bottom: 0,
height: 0,
left: 0,
right: 0,
top: 0,
width: 0,
x: 0,
y: 0,
};
return defaultDOMRect;
}
return element.getBoundingClientRect();
}

getScrollPosition = () => {
return this.foundation.getScrollPosition();
};
Expand Down

0 comments on commit 88697da

Please sign in to comment.