@@ -3,6 +3,7 @@ import React, {
33 useContext ,
44 useEffect ,
55 useLayoutEffect ,
6+ useMemo ,
67 useRef ,
78 useState ,
89} from 'react' ;
@@ -20,7 +21,15 @@ import { rafraf } from '../utils/rafraf';
2021type SectionData = Required < DrawerLayoutProps > [ 'toolbarData' ] [ number ] ;
2122
2223type DrawerSectionProps = Omit < SectionData , 'content' | 'onClick' > & {
24+ /**
25+ * If `true` will automatically open the section when first mounted. Default: `false`
26+ */
2327 autoOpen ?: boolean ;
28+ /**
29+ * Allows to control item oder in the drawer toolbar, items without the order
30+ * provided will stay unordered at the bottom of the list
31+ */
32+ order ?: number ;
2433} ;
2534
2635type DrawerActionsContextValue = {
@@ -191,17 +200,23 @@ export const DrawerAnchor: React.FunctionComponent<{
191200 }
192201 prevDrawerSectionItems . current = drawerSectionItems ;
193202 } , [ actions , drawerSectionItems ] ) ;
194- const toolbarData = drawerSectionItems . map ( ( data ) => {
195- return {
196- ...data ,
197- content : (
198- < div
199- data-drawer-section = { data . id }
200- className = { drawerSectionPortalStyles }
201- > </ div >
202- ) ,
203- } ;
204- } ) ;
203+ const toolbarData = useMemo ( ( ) => {
204+ return drawerSectionItems
205+ . map ( ( data ) => {
206+ return {
207+ ...data ,
208+ content : (
209+ < div
210+ data-drawer-section = { data . id }
211+ className = { drawerSectionPortalStyles }
212+ > </ div >
213+ ) ,
214+ } ;
215+ } )
216+ . sort ( ( { order : orderA = Infinity } , { order : orderB = Infinity } ) => {
217+ return orderB < orderA ? 1 : orderB > orderA ? - 1 : 0 ;
218+ } ) ;
219+ } , [ drawerSectionItems ] ) ;
205220 return (
206221 < DrawerLayout
207222 displayMode = { displayMode ?? DrawerDisplayMode . Embedded }
0 commit comments