Skip to content

Commit

Permalink
fix: support old refs
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Mar 11, 2019
1 parent 67519f3 commit a8be7c2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ export interface IRemoveScrollProps {
className?: string;
removeScrollBar?: boolean;

shards?: Array<React.RefObject<any>>;
shards?: Array<React.RefObject<any> | HTMLElement>;
}

const classNames = {
fullWidth: fullWidthClassName,
zeroRight: zeroRightClassName,
};

const extractRef = (ref: React.RefObject<any> | HTMLElement): HTMLElement => (
(ref && 'current' in ref) ? ref.current : ref
);

export class RemoveScroll extends React.Component<IRemoveScrollProps> {
public static classNames = classNames;

Expand All @@ -45,7 +49,7 @@ export class RemoveScroll extends React.Component<IRemoveScrollProps> {
this.disable()
}

componentDidUpdate(oldProps: RemoveScrollProps) {
componentDidUpdate(oldProps: IRemoveScrollProps) {
if (oldProps.enabled !== this.props.enabled) {
if (this.props.enabled) {
this.enable();
Expand Down Expand Up @@ -100,7 +104,7 @@ export class RemoveScroll extends React.Component<IRemoveScrollProps> {
// outside or shard event
if (!sourceEvent) {
const shardNodes = (this.props.shards || [])
.map(({current}) => current)
.map(extractRef)
.filter(Boolean)
.filter(node => node.contains(event.target));

Expand Down

0 comments on commit a8be7c2

Please sign in to comment.