Skip to content

Commit

Permalink
fix(core-components-*): fix undefined refs
Browse files Browse the repository at this point in the history
  • Loading branch information
xchaikax committed Dec 8, 2020
1 parent 75b0e7a commit ea5dac0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions packages/fade/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export const Fade = forwardRef<Element, FadeProps>((props, ref) => {
} = props;

const nodeRef = React.useRef(null);
const foreignRef = useForkRef((children as { ref: React.Ref<typeof children> }).ref, ref);
// TODO: заменить на optional chaining
const foreignRef = useForkRef(
(children && (children as { ref: React.Ref<typeof children> }).ref) || null,
ref,
);
const handleRef = useForkRef(nodeRef, foreignRef);

const handleEnter = (node: HTMLElement, isAppearing: boolean) => {
Expand Down Expand Up @@ -103,7 +107,7 @@ export const Fade = forwardRef<Element, FadeProps>((props, ref) => {
onExit={handleExit}
onExited={handleExited}
>
{ (status: string) => (
{(status: string) => (
<div
className={cn(
styles.fade,
Expand All @@ -120,7 +124,7 @@ export const Fade = forwardRef<Element, FadeProps>((props, ref) => {
: children
}
</div>
) }
)}
</Transition>
);
});
11 changes: 8 additions & 3 deletions packages/portal/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ export type PortalProps = {
export const Portal = forwardRef<Element, PortalProps>(
({ container = null, disablePortal, children }, ref) => {
const [mountNode, setMountNode] = useState<Element | null>(null);
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const handleRef = useForkRef(React.isValidElement(children) ? children.ref : null, ref);

// TODO: заменить на optional chaining
const handleRef = useForkRef(
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
React.isValidElement(children) ? (children && children.ref) || null : null,
ref,
);

useEffect(() => {
if (!disablePortal) {
Expand Down
3 changes: 2 additions & 1 deletion packages/trap-focus/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ export const TrapFocus: React.FC<TrapFocusProps> = props => {
rootRef.current = ReactDOM.findDOMNode(instance) as HTMLElement;
}, []);

// TODO: заменить на optional chaining
const handleRef = useForkRef(
(children as { ref: React.Ref<typeof children> }).ref,
(children && (children as { ref: React.Ref<typeof children> }).ref) || null,
handleOwnRef,
);

Expand Down

0 comments on commit ea5dac0

Please sign in to comment.