Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

fix: ClientRect/DOMRect is not IE11 compatible #855

Merged
merged 3 commits into from
May 10, 2019
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
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