Skip to content

Commit 1de1794

Browse files
committed
fix: 블럭 타입 선택 모달 닫는 기능에 dimmer 활용
- dimmer layer 하나를 두고 모달이 켜진 상태에서 외부 영역을 클릭하면 모달이 닫히도록 함 - 다른 블럭으로 이동하려면 더블 클릭 필요 Resolves #321
1 parent fece485 commit 1de1794

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

client/src/components/Block/TextBlock.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function TextBlock({
3030
registerRef,
3131
}: BlockProps) {
3232
const { momSocket: socket } = useSocketContext();
33-
const [isOpen, setIsOpen] = useState<boolean>(false);
3433

3534
const {
3635
syncCRDT,
@@ -46,6 +45,9 @@ function TextBlock({
4645
const { offsetRef, setOffset, clearOffset, onArrowKeyDown, offsetHandlers } =
4746
useOffset(blockRef);
4847

48+
const [isOpen, setIsOpen] = useState<boolean>(false);
49+
const onClose = () => setIsOpen(false);
50+
4951
// 리모트 연산 수행결과로 innerText 변경 시 커서의 위치 조정
5052
const updateCaretPosition = (updateOffset = 0) => {
5153
if (!blockRef.current || offsetRef.current === null) return;
@@ -212,18 +214,12 @@ function TextBlock({
212214
onHandleBlock(e);
213215
};
214216

215-
const onBlur = () => {
216-
clearOffset();
217-
setIsOpen(false);
218-
};
219-
220217
const commonHandlers = {
221218
onInput,
222219
onCompositionEnd,
223220
...offsetHandlers,
224221
onKeyDown,
225222
onPaste,
226-
onBlur,
227223
};
228224

229225
const BLOCK_TYPES = Object.values(BlockType)
@@ -249,7 +245,7 @@ function TextBlock({
249245
},
250246
readCRDT(),
251247
)}
252-
{isOpen && <BlockSelector onSelect={onSelect} />}
248+
{isOpen && <BlockSelector onClose={onClose} onSelect={onSelect} />}
253249
</>
254250
);
255251
}

client/src/components/BlockSelector/index.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,29 @@ import BlockItem from './BlockItem';
55
import style from './style.module.scss';
66

77
interface BlockSelectorProps {
8+
onClose: () => void;
89
onSelect: (arg: BlockType) => void;
910
}
1011

11-
function BlockSelector({ onSelect }: BlockSelectorProps) {
12+
function BlockSelector({ onClose, onSelect }: BlockSelectorProps) {
1213
return (
13-
<div className={style['block-selector']}>
14-
<div className={style['block-displayed']}>
15-
<strong>블록</strong>
14+
<>
15+
<div className={style['block-selector']}>
16+
<div className={style['block-displayed']}>
17+
<strong>블록</strong>
1618

17-
<ul className={style['block-list']}>
18-
{BLOCKS_TYPE.map(({ id, name, desc, thumbnail }) => (
19-
<BlockItem key={id} {...{ id, name, desc, thumbnail, onSelect }} />
20-
))}
21-
</ul>
19+
<ul className={style['block-list']}>
20+
{BLOCKS_TYPE.map(({ id, name, desc, thumbnail }) => (
21+
<BlockItem
22+
key={id}
23+
{...{ id, name, desc, thumbnail, onSelect }}
24+
/>
25+
))}
26+
</ul>
27+
</div>
2228
</div>
23-
</div>
29+
<div className={style['dimmer']} onClick={onClose}></div>
30+
</>
2431
);
2532
}
2633

client/src/components/BlockSelector/style.module.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.block-selector {
44
position: absolute;
55
z-index: 99;
6-
height: 100%;
6+
height: 280px;
77
overflow: hidden;
88

99
.block-displayed {
@@ -27,3 +27,11 @@
2727
}
2828
}
2929
}
30+
31+
.dimmer {
32+
position: fixed;
33+
top: 0;
34+
left: 0;
35+
width: 100vw;
36+
height: 100vh;
37+
}

client/src/hooks/useOffset.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export function useOffset(blockRef: React.RefObject<HTMLParagraphElement>) {
5454
};
5555

5656
const offsetHandlers = {
57-
onClick:
58-
setOffset as unknown as React.MouseEventHandler<HTMLParagraphElement>,
57+
onClick: setOffset,
58+
onBlur: clearOffset,
5959
onKeyUp: onArrowKeyup,
6060
};
6161

0 commit comments

Comments
 (0)