Skip to content

feat(tabs): add functionality of canceling a tab removal #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
inkidotcom opened this issue Jul 25, 2016 · 12 comments
Open

feat(tabs): add functionality of canceling a tab removal #786

inkidotcom opened this issue Jul 25, 2016 · 12 comments

Comments

@inkidotcom
Copy link

I'm trying to display an alert before a tab is removed however I'm not able to find a way to cancel the tab removal. I'm sure I'm missing something simple, but I can't find the solution.

@adrianfaciu
Copy link

You have the removable property on the Tab component. If false, the remove button will not be displayed. Can this work for you ?

@slubowsky
Copy link

@inkidotcom I have a similar issue, want to veto tab selection. See #699. Perhaps my workaround there might work for you as well

@inkidotcom
Copy link
Author

@slubowsky not quite, but thanks.

from components/tabs/tabset.component.ts

public removeTab(tab:TabDirective):void {
    let index = this.tabs.indexOf(tab);
    if (index === -1 || this.isDestroyed) {
      return;
    }
    // Select a new tab if the tab to be removed is selected and not destroyed
    if (tab.active && this.hasAvailableTabs(index)) {
      let newActiveIndex = this.getClosestTabIndex(index);
      this.tabs[newActiveIndex].active = true;
    }

    tab.removed.emit(tab);
    this.tabs.splice(index, 1);
  }

so it looks like the last line is firing no matter what:

this.tabs.splice(index, 1);

@inkidotcom
Copy link
Author

@adrianfaciu I guess I can create my own remove button instead of using the built-in option. I was just looking for a way to stop the removal of the tab using the existing remove handler functionality.

@valorkin
Copy link
Member

valorkin commented Oct 3, 2016

@inkidotcom I am still looking for a nice solution to prevent user actions
user -> bs comp -> my app code -> bs comp

@valorkin valorkin self-assigned this Oct 3, 2016
@xwb1989
Copy link

xwb1989 commented Dec 21, 2016

I'm very in need of this feature as well.

A possible API in my mind can be exposing an API in Tab:

onTabRemovalHandler: () => Promise<boolean>

Before BS comp really removes the tab, it calls this user-defined callback first, and if it resolves to true, continue the removal; abort otherwise.

@valorkin
Copy link
Member

better to create onChange on onRemove

@studentIvan
Copy link

👍 +1 to this bug

@srikarshastry
Copy link

any update on this please? I'm facing the similar. Any help/dirty hack(workaround) is greatly appreciated

@epitomz
Copy link

epitomz commented Feb 15, 2018

@Hotdog1987 you can just implement your own button to close the modal depending on a modal or whatever you want. You just need to hide the bs-remove-tab with some css code and you're done.

P.S: your closing method should be just something like this.tabs.splice(this.tabs.indexOf(tab), 1);

@DebolaA
Copy link

DebolaA commented Aug 30, 2019

having the same issue too;
i will implement my own remove button;
this request should be dealt with please.
thank you

@neo1380
Copy link

neo1380 commented Aug 15, 2020

I have fixed it by introducing two new input properties to the tab. the two properties are

  • lazyRemove [ boolean ]
  • canRemove [ boolean ]

Inside remove method, i am validating the lazyRemove, if it is true then we simply return without removing the tab. basically blocking the below line:

if (tab.lazyRemove) {
return;
}

this.tabs.splice(index, 1);

So, now we emit an event to the consuming component that remove event is triggered. On listening to this event, we can display a modal with buttons as yes or no. And on clicking of Yes, which confirms that we can remove the button, we change the canRemove boolean to true.

Now, when this is set to true, we trigger the method to remove the tab with lazyRemove setting to false;

valorkin added a commit that referenced this issue May 26, 2025
- Add beforeRemove event to TabDirective that emits before tab removal
- Allow cancellation by calling event.preventDefault() in the event handler
- Update TabsetComponent.removeTab() to check for cancellation before proceeding
- Maintain full backward compatibility with existing removed event
- Add comprehensive unit tests for all cancellation scenarios
- Add E2E tests to verify tab removal cancellation behavior

Fixes #786

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests