-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Popover): support bind ref with children (#1473)
* fix(Popover): support bind ref with children * fix(Dropdown): fix type issue * fix(Popover): remove inject classname * fix(Popover): fix lint issue Co-authored-by: Zhang Rui <zhangrui@growingio.com>
- Loading branch information
Ryan Zhang
and
Zhang Rui
committed
Nov 16, 2021
1 parent
e19fe2c
commit d56229a
Showing
8 changed files
with
142 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import React from 'react'; | ||
import { isMemo } from 'react-is'; | ||
|
||
const composeRef = <T>(...refs: React.Ref<T>[]): React.Ref<T> => (node: T) => { | ||
refs.forEach((ref) => { | ||
if (typeof ref === 'function') { | ||
ref(node); | ||
} else if (typeof ref === 'object' && ref && 'current' in ref) { | ||
// eslint-disable-next-line no-param-reassign | ||
(ref as any).current = node; | ||
} | ||
}); | ||
}; | ||
export const composeRef = | ||
<T>(...refs: React.Ref<T>[]): React.Ref<T> => | ||
(node: T) => { | ||
refs.forEach((ref) => { | ||
if (typeof ref === 'function') { | ||
ref(node); | ||
} else if (typeof ref === 'object' && ref && 'current' in ref) { | ||
// eslint-disable-next-line no-param-reassign | ||
(ref as any).current = node; | ||
} | ||
}); | ||
}; | ||
|
||
export function supportRef(nodeOrComponent: any): boolean { | ||
if (typeof nodeOrComponent !== 'object') { | ||
return false; | ||
} | ||
const type = isMemo(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type; | ||
|
||
// Function component node | ||
if (typeof type === 'function' && !type.prototype?.render) { | ||
return false; | ||
} | ||
|
||
// Class component | ||
if (typeof nodeOrComponent === 'function' && !nodeOrComponent.prototype?.render) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
export default composeRef; |
d56229a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: