-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Dispatch cancelable events with createEventDispatcher #4623
Comments
I for one support this proposal. Non-bubble is alright, but banning cancellable seems pointless. If allow to cancel, this opens up possibility for some meaningful use cases. For example, a Tabs component. <script lang='ts'>
export let selectedTabKey
export let tabs: { key: string; name: string }[] = []
const selectTab = (tabKey: string) => {
const success = dispatch('selectTab', tabKey)
if (success) {
selectedTabKey = tabKey
}
}
</script>
<div class='tab-bar'>
{#each tabs as tab (tab.key)}
<div class="tab" on:click={() => selectTab(tab.key)}>{tab.name}</div>
{/each}
</div>
<div class="content">
<slot {selectedTabKey} />
</div> If custom event is cancelable, this opens up a way for parent component to communicate to child component the intention that "I wanna take over control of your behavior". |
My two cent to add: I prefer the |
Just ran into this missing feature when trying to build a Dropdown component. Would be great to be able to allow the containing component to cancel an event. I am hoping to see functionality like the following: <script>
let showDropdown = false;
function handleClickButton() {
const event = dispatch('open');
if(!event.defaultPrevented()) {
showDropdown = true;
}
}
function handleClickOutside() {
const event = dispatch('close');
if(!event.defaultPrevented()) {
showDropdown = false;
}
}
</script> |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Any chance of this landing anytime soon? Would help us library authors a lot, until then we're stuck with React style |
The internal |
Any chance we can get #7064 merged? We're also looking forward to getting this feature. |
This is supported now in 3.48.0. |
From the docs:
I understand why they couldn't bubble, but is there any reason why cancelable event aren't allowed ? It would only require adding one line in
createEventDispatcher
declaration (from /src/runtime/internal/lifecycle.ts)and a slightly different signature for
custom_event
(from /src/runtime/internal/dom.ts)The text was updated successfully, but these errors were encountered: