dockview icon indicating copy to clipboard operation
dockview copied to clipboard

onWillClose event for panels

Open mgray88 opened this issue 10 months ago • 2 comments

Is your feature request related to a problem? Please describe. I would like to be able to detect when a panel is being closed so I can either prevent it or save state.

Describe the solution you'd like An onWillClose event handler passed in to component props alongside onDidActiveChange and others.

Describe alternatives you've considered Tried to use closeActionOverride in a tab renderer and dispatching an event to the tab. The closest I could get was the following, which doesn't dispatch to the dom element pertaining to the rendered component:

props.containerApi
  .getPanel(id)
  ?.view.content.element.dispatchEvent(new FocusEvent('focus'))

eta: I have defaultRenderer set to always so the dom elements are outside of the scope of the event above.

mgray88 avatar Feb 07 '25 13:02 mgray88

Second this! Would be great to have this event either as a way to prevent a close or to get a notification to update states.

PhilCCMG avatar Feb 15 '25 00:02 PhilCCMG

Still new to Dockview but a possible workaround is to use closeActionOverride from the DockviewDefaultTab. Obviously this only works when the panel gets closed with the default X-button in the tab bar.

const CustomTabCmp: React.FunctionComponent<IDockviewPanelHeaderProps> = props => {
  return (
    <DockviewDefaultTab
      {...props}
      closeActionOverride={() => {
        console.log('CLOSE OVERRIDE: Do nothing!');
      }}
    />
  );
};

const DockViewCmp = () => <DockviewReact defaultTabComponent={CustomTabCmp} />

cbn-falias avatar Jun 26 '25 08:06 cbn-falias