@@ -13,6 +13,7 @@ import {
1313  AnchoredOverlayProps , 
1414  Spinner , 
1515  Text , 
16+   ActionListProps , 
1617}  from  '../../../src/index' 
1718import  { ActionListContainerContext }  from  '../../../src/ActionList/ActionListContainerContext' 
1819import  { useSlots }  from  '../../hooks/useSlots' 
@@ -24,12 +25,14 @@ const SelectPanelContext = React.createContext<{
2425  onClearSelection : undefined  |  ( ( )  =>  void ) 
2526  searchQuery : string 
2627  setSearchQuery : ( )  =>  void 
28+   selectionVariant : ActionListProps [ 'selectionVariant' ]  |  'instant' 
2729} > ( { 
2830  title : '' , 
2931  onCancel : ( )  =>  { } , 
3032  onClearSelection : undefined , 
3133  searchQuery : '' , 
3234  setSearchQuery : ( )  =>  { } , 
35+   selectionVariant : 'multiple' , 
3336} ) 
3437
3538// @ts -ignore todo 
@@ -56,9 +59,9 @@ const SelectPanel = props => {
5659    if  ( props . open  ===  undefined )  setInternalOpen ( false ) 
5760    if  ( typeof  props . onCancel  ===  'function' )  props . onCancel ( ) 
5861  } 
59-    //  @ts -ignore todo 
60-   const  onInternalSubmit  =  event  =>  { 
61-     event . preventDefault ( ) 
62+ 
63+   const  onInternalSubmit  =  ( event ?:  React . SyntheticEvent )  =>  { 
64+     event ? .preventDefault ( )   // there is no event with selectionVariant=instant 
6265    if  ( props . open  ===  undefined )  setInternalOpen ( false ) 
6366    if  ( typeof  props . onSubmit  ===  'function' )  props . onSubmit ( event ) 
6467  } 
@@ -67,6 +70,10 @@ const SelectPanel = props => {
6770    if  ( typeof  props . onSubmit  ===  'function' )  props . onClearSelection ( ) 
6871  } 
6972
73+   const  internalAfterSelect  =  ( )  =>  { 
74+     if  ( props . selectionVariant  ===  'instant' )  onInternalSubmit ( ) 
75+   } 
76+ 
7077  /* Search/Filter */ 
7178  const  [ searchQuery ,  setSearchQuery ]  =  React . useState ( '' ) 
7279
@@ -96,6 +103,7 @@ const SelectPanel = props => {
96103            searchQuery, 
97104            // @ts -ignore todo 
98105            setSearchQuery, 
106+             selectionVariant : props . selectionVariant , 
99107          } } 
100108        > 
101109          < Box 
@@ -126,7 +134,9 @@ const SelectPanel = props => {
126134                  container : 'SelectPanel' , 
127135                  listRole : 'listbox' , 
128136                  selectionAttribute : 'aria-selected' , 
129-                   selectionVariant : props . selectionVariant  ||  'multiple' , 
137+                   selectionVariant :
138+                     props . selectionVariant  ===  'instant'  ? 'single'  : props . selectionVariant  ||  'multiple' , 
139+                   afterSelect : internalAfterSelect , 
130140                } } 
131141              > 
132142                { childrenInBody } 
@@ -243,7 +253,15 @@ const SelectPanelSearchInput = props => {
243253SelectPanel . SearchInput  =  SelectPanelSearchInput 
244254
245255const  SelectPanelFooter  =  ( { ...props } )  =>  { 
246-   const  { onCancel}  =  React . useContext ( SelectPanelContext ) 
256+   const  { onCancel,  selectionVariant}  =  React . useContext ( SelectPanelContext ) 
257+ 
258+   const  hidePrimaryActions  =  selectionVariant  ===  'instant' 
259+ 
260+   if  ( hidePrimaryActions  &&  ! props . children )  { 
261+     // nothing to render 
262+     // todo: we can inform them the developer footer will render nothing 
263+     return  null 
264+   } 
247265
248266  return  ( 
249267    < Box 
@@ -255,23 +273,26 @@ const SelectPanelFooter = ({...props}) => {
255273        borderColor : 'border.default' , 
256274      } } 
257275    > 
258-       < div > { props . children } </ div > 
259-       < Box  sx = { { display : 'flex' ,  gap : 2 } } > 
260-         < Button  size = "small"  type = "button"  onClick = { ( )  =>  onCancel ( ) } > 
261-           Cancel
262-         </ Button > 
263-         < Button  size = "small"  type = "submit"  variant = "primary" > 
264-           Save
265-         </ Button > 
266-       </ Box > 
276+       < Box  sx = { { flexGrow : hidePrimaryActions  ? 1  : 0 } } > { props . children } </ Box > 
277+ 
278+       { hidePrimaryActions  ? null  : ( 
279+         < Box  sx = { { display : 'flex' ,  gap : 2 } } > 
280+           < Button  size = "small"  type = "button"  onClick = { ( )  =>  onCancel ( ) } > 
281+             Cancel
282+           </ Button > 
283+           < Button  size = "small"  type = "submit"  variant = "primary" > 
284+             Save
285+           </ Button > 
286+         </ Box > 
287+       ) } 
267288    </ Box > 
268289  ) 
269290} 
270291SelectPanel . Footer  =  SelectPanelFooter 
271292
272293// @ts -ignore todo 
273294SelectPanel . SecondaryButton  =  props  =>  { 
274-   return  < Button  { ...props }  size = "small"  type = "button"  /> 
295+   return  < Button  { ...props }  size = "small"  type = "button"  block   /> 
275296} 
276297// SelectPanel.SecondaryLink = props => { 
277298//   return <a {...props}>{props.children}</a> 
0 commit comments