Skip to content
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

fix(ui): Select에 createPortal 적용 #218

Merged
merged 1 commit into from
Nov 28, 2024
Merged
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
17 changes: 12 additions & 5 deletions packages/ui/Input/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useRef, useEffect, useCallback, createContext, useContext } from 'react';
import { IconChevronDown, IconUser } from '@sopt-makers/icons';
import { createPortal } from 'react-dom';
import * as S from './style.css';

export interface Option<T> {
Expand Down Expand Up @@ -176,16 +177,22 @@ interface SelectMenuProps {

// SelectMenu 컴포넌트: 옵션 목록을 렌더링
function SelectMenu({ children, className }: SelectMenuProps) {
const { open, optionsRef, calcMaxHeight } = useSelectContext();
const { open, optionsRef, calcMaxHeight, buttonRef } = useSelectContext();

if (!open) {
const buttonRect = buttonRef.current?.getBoundingClientRect();

if (!open || !buttonRect) {
return null;
}

return (
<ul className={`${S.optionList} ${className}`} ref={optionsRef} style={{ maxHeight: calcMaxHeight() }}>
const top = `${buttonRect.top + buttonRect.height}px`;
const left = `${buttonRect.left}px`;

return createPortal(
<ul className={`${S.optionList} ${className}`} ref={optionsRef} style={{ top, left, maxHeight: calcMaxHeight() }}>
{children}
</ul>
</ul>,
document.body,
);
}

Expand Down
14 changes: 11 additions & 3 deletions packages/ui/Input/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,26 @@ export const optionList = style({
'borderRadius': '13px',
'minWidth': '160px',
'background': theme.colors.gray800,
'overflow': 'scroll',
'overflowY': 'auto',
'transformOrigin': 'top',
'animation': `${fadeIn} 0.5s forwards`,
'overflowX': 'hidden',
'zIndex': 24,

'::-webkit-scrollbar': {
width: '14px',
},
'::-webkit-scrollbar-track': {
background: 'transparent',
},
'::-webkit-scrollbar-thumb': {
background: theme.colors.gray500,
backgroundClip: 'padding-box',
border: '4px solid transparent',
border: '2px solid transparent',
borderTopWidth: '3px',
borderBottomWidth: '3px',
boxShadow: `inset -3px 0 0 ${theme.colors.gray800}`,
borderRadius: '8px',
borderRadius: '16px',
},
});

Expand Down