Commit c279499 1 parent e0f9774 commit c279499 Copy full SHA for c279499
File tree 2 files changed +18
-1
lines changed
src/components/Design/SelectBox
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,16 @@ const meta = {
8
8
9
9
type Story = StoryObj < typeof meta > ;
10
10
11
+ interface OptionInterface {
12
+ name : string ;
13
+ value : string ;
14
+ }
15
+
16
+ function setSelectOption ( result : OptionInterface ) {
17
+ console . log ( result ) ;
18
+ return result ;
19
+ }
20
+
11
21
export const Primary : Story = {
12
22
args : {
13
23
options : [
@@ -17,6 +27,7 @@ export const Primary: Story = {
17
27
18
28
defaultName : "학년" ,
19
29
isRequired : true ,
30
+ setSelectOption : setSelectOption ,
20
31
} ,
21
32
} ;
22
33
Original file line number Diff line number Diff line change 4
4
* Copyright (c) 2024 Your Company
5
5
*/
6
6
7
- import { useState , useRef } from "react" ;
7
+ import { useState , useRef , useEffect } from "react" ;
8
8
9
9
import * as S from "./emotion" ;
10
10
@@ -16,12 +16,14 @@ interface SelectboxProps {
16
16
options : OptionInterface [ ] ;
17
17
defaultName : string ;
18
18
isRequired : boolean ;
19
+ setSelectOption : ( result : OptionInterface ) => OptionInterface ; // setState or object
19
20
}
20
21
21
22
export default function SelectBox ( {
22
23
options,
23
24
defaultName = "값을 선택하세요." ,
24
25
isRequired = false ,
26
+ setSelectOption,
25
27
} : SelectboxProps ) {
26
28
const [ isOpen , setIsOpen ] = useState < boolean > ( false ) ;
27
29
const [ selectedName , setSelectedName ] = useState ( defaultName ) ;
@@ -37,6 +39,10 @@ export default function SelectBox({
37
39
setIsChanged ( true ) ;
38
40
}
39
41
42
+ useEffect ( ( ) => {
43
+ if ( selectedIndex >= 0 ) setSelectOption ( options [ selectedIndex ] ) ;
44
+ } , [ selectedIndex ] ) ;
45
+
40
46
return (
41
47
< S . SelectBoxWrap
42
48
onClick = { ( ) => setIsOpen ( ! isOpen ) }
You can’t perform that action at this time.
0 commit comments