@@ -29,6 +29,7 @@ export interface ResizableWidthHandlers {
2929/** Persist on drag end to avoid a storage write on every animation frame. */
3030export function useResizableWidth ( options : UseResizableWidthOptions ) : {
3131 readonly width : number ;
32+ readonly setWidth : ( width : number ) => void ;
3233 readonly handlers : ResizableWidthHandlers ;
3334} {
3435 const { storageKey, defaultWidth, minWidth, maxWidth, edge } = options ;
@@ -55,6 +56,16 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
5556
5657 const clampedWidth = clamp ( widthState . width ) ;
5758
59+ const commitWidth = ( nextStorageKey : string , nextWidth : number ) => {
60+ // Resizing remains usable for this session when browser storage is unavailable.
61+ setWidthState ( { storageKey : nextStorageKey , width : nextWidth } ) ;
62+ try {
63+ setLocalStorageItem ( nextStorageKey , nextWidth , WidthSchema ) ;
64+ } catch ( error ) {
65+ console . error ( "Could not persist panel width." , error ) ;
66+ }
67+ } ;
68+
5869 const drag = useResizeDrag < HTMLElement > ( ( event ) => {
5970 const host = event . currentTarget . parentElement ;
6071 // Disable drag transitions through transition-property; the host renders transition-duration.
@@ -72,12 +83,7 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
7283 return nextWidth ;
7384 } ,
7485 finish ( finalWidth ) {
75- setWidthState ( { storageKey : startStorageKey , width : finalWidth } ) ;
76- try {
77- setLocalStorageItem ( startStorageKey , finalWidth , WidthSchema ) ;
78- } catch ( error ) {
79- console . error ( "Could not persist panel width." , error ) ;
80- }
86+ commitWidth ( startStorageKey , finalWidth ) ;
8187 } ,
8288 cleanup ( committed ) {
8389 host ?. style . removeProperty ( "transition-property" ) ;
@@ -94,6 +100,7 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
94100
95101 return {
96102 width : clampedWidth ,
103+ setWidth : ( value ) => commitWidth ( storageKey , clamp ( value ) ) ,
97104 handlers : {
98105 ref : drag . ref ,
99106 onPointerDown : drag . onPointerDown ,
0 commit comments