Skip to content
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

(fix) missing search event #1550

Closed
wants to merge 1 commit into from

Conversation

jameslieu
Copy link

Hello,

I was getting a TypeScript error when listening to the "search" DOM event. This event is triggered when you click the "X" that appears in an input type=search field.

image

Here is an article about the "X" or clear button for more context: https://www.freecodecamp.org/news/targeting-click-of-clear-button-x-on-input-field/

I had a look and there was a similar fix done in this raised issue: #220
Adding the onsearch property here has made the error go away. Hope this helps

@jasonlyu123
Copy link
Member

jasonlyu123 commented Jul 6, 2022

Thanks for the PR. But according to MDN, this event is non-standard that is not available in some browsers. And typescript's dom.d.ts also doesn't have this event. So I think we won't add this.

But if you do want to use it you can enhance the typing by yourself. You can create a .d.ts file and make sure this file is included in your tsconfig/jsconfig

declare namespace svelte.JSX {
    interface DOMAttributes<T extends EventTarget> {
        onsearch?: EventHandler<Event, T> | undefined | null;
    }
}

But do keep in mind that we might update the custom event type def in the future(#1549, #1352). And you would have to update the type def to the following.

declare namespace svelteHTML {
    interface DOMAttributes<T extends EventTarget> {
        "on:search"?: EventHandler<Event, T> | undefined | null;
    }
}

@jameslieu
Copy link
Author

Thank you for looking at this and your code example to enhance that event myself @jasonlyu123.

I'll close the PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants