Skip to content

Commit

Permalink
feat(AsideHeader)!: add ref prop for popup-anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunory committed Oct 4, 2023
1 parent d5b2f6d commit 48f83ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/components/AsideHeader/AsideHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ASIDE_HEADER_COMPACT_WIDTH, ASIDE_HEADER_EXPANDED_WIDTH} from '../consta
import {Content} from '../Content';

import {AsideHeaderContextProvider, AsideHeaderInnerContextProvider} from './AsideHeaderContext';
import {AsideHeaderGeneralProps, AsideHeaderDefaultProps, AsideHeaderInnerProps} from './types';
import {AsideHeaderGeneralProps, AsideHeaderDefaultProps} from './types';

import {FirstPanel} from './components';
import {b} from './utils';
Expand All @@ -18,7 +18,7 @@ export interface AsideHeaderProps
extends AsideHeaderGeneralProps,
Partial<AsideHeaderDefaultProps> {}

export const AsideHeader = (props: AsideHeaderInnerProps) => {
export const AsideHeader = React.forwardRef<HTMLDivElement, AsideHeaderProps>((props, ref) => {
const {className, compact, onClosePanel} = props;

const size = compact ? ASIDE_HEADER_COMPACT_WIDTH : ASIDE_HEADER_EXPANDED_WIDTH;
Expand All @@ -43,7 +43,7 @@ export const AsideHeader = (props: AsideHeaderInnerProps) => {
<div className={b({compact}, className)}>
<div className={b('pane-container')}>
{/* First Panel */}
<FirstPanel />
<FirstPanel ref={ref} />
{/* Second Panel */}
<Content
size={size}
Expand All @@ -55,4 +55,4 @@ export const AsideHeader = (props: AsideHeaderInnerProps) => {
</AsideHeaderInnerContextProvider>
</AsideHeaderContextProvider>
);
};
});
6 changes: 3 additions & 3 deletions src/components/AsideHeader/components/FirstPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Header} from './Header';
import {CollapseButton} from './CollapseButton';
import {Panels} from './Panels';

export const FirstPanel = () => {
export const FirstPanel = React.forwardRef<HTMLDivElement>((_props, ref) => {
const {
size,
onItemClick,
Expand All @@ -20,7 +20,7 @@ export const FirstPanel = () => {
compact,
} = useAsideHeaderInnerContext();

const asideRef = useRef<HTMLDivElement>(null);
const asideRef = ref || useRef<HTMLDivElement>(null);

return (
<>
Expand Down Expand Up @@ -52,4 +52,4 @@ export const FirstPanel = () => {
<Panels />
</>
);
};
});
2 changes: 1 addition & 1 deletion src/components/AsideHeader/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AsideHeaderGeneralProps {
renderFooter?: (data: {
size: number;
compact: boolean;
asideRef: React.RefObject<HTMLDivElement>;
asideRef: React.ForwardedRef<HTMLDivElement>;
}) => React.ReactNode;
onClosePanel?: () => void;
onChangeCompact?: (compact: boolean) => void;
Expand Down

0 comments on commit 48f83ce

Please sign in to comment.