@@ -82,7 +82,7 @@ storiesOf('ComboBox', module)
8282 . add (
8383 'with mapped items (defaultItem and items undef)' ,
8484 ( ) => (
85- < ComboBoxWithMap defaultOpen defaultSelectedKey = "two" />
85+ < ComboBoxWithMap defaultSelectedKey = "two" />
8686 )
8787 )
8888 . add (
@@ -190,29 +190,6 @@ storiesOf('ComboBox', module)
190190 </ Flex >
191191 )
192192 )
193- . add (
194- 'isOpen' ,
195- ( ) => < ControlledOpenCombobox isOpen allowsCustomValue defaultSelectedKey = "two" /> ,
196- { note : 'Combobox needs focus to show dropdown.' }
197- )
198- . add (
199- 'defaultOpen' ,
200- ( ) => (
201- < Flex direction = "column" >
202- < TextField label = "Email" />
203- < ComboBox label = "Combobox" defaultOpen { ...actions } >
204- < Item key = "one" > Item One</ Item >
205- < Item key = "two" textValue = "Item Two" >
206- < Copy size = "S" />
207- < Text > Item Two</ Text >
208- </ Item >
209- < Item key = "three" > Item Three</ Item >
210- </ ComboBox >
211- < TextField label = "Name" />
212- </ Flex >
213- ) ,
214- { note : 'Combobox needs focus to show dropdown.' }
215- )
216193 . add (
217194 'disabled keys' ,
218195 ( ) => (
@@ -426,30 +403,6 @@ storiesOf('ComboBox', module)
426403 < ControlledKeyComboBox defaultInputValue = "Blah" selectedKey = "2" disabledKeys = { [ '2' , '6' ] } />
427404 )
428405 )
429- . add (
430- 'inputValue and isOpen (controlled)' ,
431- ( ) => (
432- < ControlledValueOpenCombobox />
433- )
434- )
435- . add (
436- 'selectedKey and isOpen (controlled)' ,
437- ( ) => (
438- < ControlledKeyOpenCombobox />
439- )
440- )
441- . add (
442- 'inputValue, selectedKey, and isOpen (controlled)' ,
443- ( ) => (
444- < AllControlledOpenComboBox selectedKey = "2" inputValue = "Kangaroo" disabledKeys = { [ '2' , '6' ] } />
445- )
446- )
447- . add (
448- 'inputValue, selectedKey, isOpen, allowsCustomValue (controlled)' ,
449- ( ) => (
450- < AllControlledOpenComboBox selectedKey = "2" inputValue = "Kangaroo" disabledKeys = { [ '2' , '6' ] } allowsCustomValue />
451- )
452- )
453406 . add (
454407 'custom filter' ,
455408 ( ) => (
@@ -899,139 +852,6 @@ let CustomValueComboBox = (props) => {
899852 ) ;
900853} ;
901854
902- let ControlledOpenCombobox = ( props ) => {
903- let [ isOpen , setOpen ] = React . useState ( props . isOpen ) ;
904-
905- return (
906- < Flex direction = "column" >
907- < TextField label = "Email" />
908- < ComboBox label = "Combobox" { ...mergeProps ( props , actions ) } isOpen = { isOpen } onOpenChange = { setOpen } >
909- < Item key = "one" > Item One</ Item >
910- < Item key = "two" textValue = "Item Two" >
911- < Copy size = "S" />
912- < Text > Item Two</ Text >
913- </ Item >
914- < Item key = "three" > Item Three</ Item >
915- </ ComboBox >
916- < TextField label = "Name" />
917- </ Flex >
918- ) ;
919- } ;
920-
921- let ControlledValueOpenCombobox = ( props ) => {
922- let [ fieldState , setFieldState ] = React . useState ( {
923- isOpen : false ,
924- inputValue : ''
925- } ) ;
926-
927- let onInputChange = ( value : string ) => {
928- setFieldState ( {
929- isOpen : true ,
930- inputValue : value
931- } ) ;
932- } ;
933-
934- let onOpenChange = ( isOpen : boolean ) => {
935- setFieldState ( prevState => ( {
936- isOpen : isOpen ,
937- inputValue : prevState . inputValue
938- } ) ) ;
939- } ;
940-
941- let onSelectionChange = ( key ) => {
942- setFieldState ( {
943- isOpen : false ,
944- inputValue : items . find ( item => item . id === key ) ?. name ?? ''
945- } ) ;
946- } ;
947-
948- return (
949- < ComboBox label = "Combobox" { ...mergeProps ( props , actions ) } defaultItems = { items } isOpen = { fieldState . isOpen } onOpenChange = { onOpenChange } inputValue = { fieldState . inputValue } onInputChange = { onInputChange } onSelectionChange = { onSelectionChange } >
950- { ( item : any ) => < Item > { item . name } </ Item > }
951- </ ComboBox >
952- ) ;
953- } ;
954-
955- let ControlledKeyOpenCombobox = ( props ) => {
956- let [ fieldState , setFieldState ] = React . useState ( {
957- isOpen : false ,
958- selectedKey : 'two'
959- } ) ;
960-
961- let onSelectionChange = ( key : string ) => {
962- setFieldState ( {
963- isOpen : false ,
964- selectedKey : key
965- } ) ;
966- } ;
967-
968- let onOpenChange = ( isOpen : boolean ) => {
969- setFieldState ( prevState => ( {
970- isOpen : isOpen ,
971- selectedKey : prevState . selectedKey
972- } ) ) ;
973- } ;
974-
975- return (
976- < ComboBox label = "Combobox" { ...mergeProps ( props , actions ) } isOpen = { fieldState . isOpen } onOpenChange = { onOpenChange } selectedKey = { fieldState . selectedKey } onSelectionChange = { onSelectionChange } >
977- < Item key = "one" > Item One</ Item >
978- < Item key = "two" textValue = "Item Two" >
979- < Copy size = "S" />
980- < Text > Item Two</ Text >
981- </ Item >
982- < Item key = "three" > Item Three</ Item >
983- </ ComboBox >
984- ) ;
985- } ;
986-
987- function AllControlledOpenComboBox ( props ) {
988- let [ fieldState , setFieldState ] = React . useState ( {
989- isOpen : false ,
990- selectedKey : props . selectedKey ,
991- inputValue : props . inputValue
992- } ) ;
993-
994- let list = useTreeData ( {
995- initialItems : withSection
996- } ) ;
997-
998- let onSelectionChange = ( key : React . Key ) => {
999- setFieldState ( prevState => ( {
1000- isOpen : false ,
1001- inputValue : list . getItem ( key ) ?. value . name ?? ( props . allowsCustomValue ? prevState . inputValue : '' ) ,
1002- selectedKey : key
1003- } ) ) ;
1004- } ;
1005-
1006- let onInputChange = ( value : string ) => {
1007- setFieldState ( prevState => ( {
1008- isOpen : true ,
1009- inputValue : value ,
1010- selectedKey : value === '' ? null : prevState . selectedKey
1011- } ) ) ;
1012- } ;
1013-
1014- let onOpenChange = ( isOpen : boolean ) => {
1015- setFieldState ( prevState => ( {
1016- isOpen,
1017- inputValue : prevState . inputValue ,
1018- selectedKey : prevState . selectedKey
1019- } ) ) ;
1020- } ;
1021-
1022- return (
1023- < div >
1024- < ComboBox allowsCustomValue = { props . allowsCustomValue } disabledKeys = { props . disabledKeys } selectedKey = { fieldState . selectedKey } inputValue = { fieldState . inputValue } defaultItems = { list . items } label = "Combobox" isOpen = { fieldState . isOpen } onOpenChange = { onOpenChange } onInputChange = { onInputChange } onSelectionChange = { onSelectionChange } onBlur = { action ( 'onBlur' ) } onFocus = { action ( 'onFocus' ) } >
1025- { item => (
1026- < Section items = { item . children } title = { item . value . name } >
1027- { item => < Item > { item . value . name } </ Item > }
1028- </ Section >
1029- ) }
1030- </ ComboBox >
1031- </ div >
1032- ) ;
1033- }
1034-
1035855function ResizeCombobox ( ) {
1036856 let [ size , setSize ] = useState ( true ) ;
1037857
0 commit comments