Skip to content

Remove SSR error #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 13 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import React, {
useState,
useRef,
useEffect,
forwardRef,
useEffect,
useImperativeHandle,
useRef,
useState,
} from 'react';
import ReactDOM from 'react-dom';
import { PopupProps, PopupActions } from './types';
import {
useIsomorphicLayoutEffect,
useOnClickOutside,
useOnEscape,
useRepositionOnResize,
useOnClickOutside,
useTabbing,
useIsomorphicLayoutEffect,
} from './hooks';
import { PopupActions, PopupProps } from './types';

import './index.css';

import styles from './styles';
import calculatePosition from './Utils';

let popupIdCounter = 0;
// let popupIdCounter = 0;

const getRootPopup = () => {
let PopupRoot = document.getElementById('popup-root');
Expand All @@ -37,6 +37,7 @@ const getRootPopup = () => {
export const Popup = forwardRef<PopupActions, PopupProps>(
(
{
id = undefined,
trigger = null,
onOpen = () => {},
onClose = () => {},
Expand Down Expand Up @@ -70,7 +71,6 @@ export const Popup = forwardRef<PopupActions, PopupProps>(
const contentRef = useRef<HTMLElement>(null);
const arrowRef = useRef<HTMLDivElement>(null);
const focusedElBeforeOpen = useRef<Element | null>(null);
const popupId = useRef<string>(`popup-${++popupIdCounter}`);

const isModal = modal ? true : !trigger;
const timeOut = useRef<any>(0);
Expand Down Expand Up @@ -210,7 +210,7 @@ export const Popup = forwardRef<PopupActions, PopupProps>(
const triggerProps: any = {
key: 'T',
ref: triggerRef,
'aria-describedby': popupId.current,
'aria-describedby': id,
};
const onAsArray = Array.isArray(on) ? on : [on];
for (let i = 0, len = onAsArray.length; i < len; i++) {
Expand Down Expand Up @@ -251,7 +251,7 @@ export const Popup = forwardRef<PopupActions, PopupProps>(
className !== ''
? className
.split(' ')
.map(c => `${c}-content`)
.map((c) => `${c}-content`)
.join(' ')
: ''
}`,
Expand All @@ -278,7 +278,7 @@ export const Popup = forwardRef<PopupActions, PopupProps>(
{...addWarperAction()}
key="C"
role={isModal ? 'dialog' : 'tooltip'}
id={popupId.current}
id={id}
>
{arrow && !isModal && (
<div ref={arrowRef} style={styles.popupArrow}>
Expand All @@ -288,7 +288,7 @@ export const Popup = forwardRef<PopupActions, PopupProps>(
className !== ''
? className
.split(' ')
.map(c => `${c}-arrow`)
.map((c) => `${c}-arrow`)
.join(' ')
: ''
}`}
Expand Down Expand Up @@ -322,7 +322,7 @@ export const Popup = forwardRef<PopupActions, PopupProps>(
className !== ''
? className
.split(' ')
.map(c => `${c}-overlay`)
.map((c) => `${c}-overlay`)
.join(' ')
: ''
}`}
Expand Down
1 change: 1 addition & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type PopupActions = {
toggle: () => void;
};
export interface PopupProps {
id?: string | number;
trigger?: JSX.Element | ((isOpen: boolean) => JSX.Element);
open?: boolean;
disabled?: boolean;
Expand Down