How do I extend HTML element
See original GitHub issueFor 300ms click delay problem, I need attach four events to a element (onClick onTouchStart onTouchMove onTouchEnd) .It makes a bit tedious that there are so many elements to be clickable.
I can create a element, maybe named <Tap />
, and receive property ontap and attache four events to the element to implement tap event. But I think it is bad for semantic, tap is a action.
So, the question is how I can extend HTML tag like div, a, em to support tap event, do you have any other ideas for this problem?
Thanks.
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How To Extend A Native HTML Element | by Danny Moerkerke
By extending the native <a> tag, we can simply add an is attribute to indicate it is a client-side link, so it won't...
Read more >Using custom elements - Web Components | MDN
Customized built-in elements inherit from basic HTML elements. To create one of these, you have to specify which element they extend (as ...
Read more >Extending an HTML Element - javascript - Stack Overflow
Making a web component that extends HTMLElement and then using its tag on the page works fine.
Read more >Custom Elements v1 - Reusable Web Components
Extending HTMLElement ensures the custom element inherits the entire DOM API and means any properties/methods that you add to the class become ...
Read more >Custom elements - The Modern JavaScript Tutorial
We can extend and customize built-in HTML elements by inheriting from their classes. For example, buttons are instances of HTMLButtonElement , ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We don’t have an exposed way to extend the built-in event system. Essentially the problem is that these extensions wouldn’t be scoped to a component. It is a global set up and different components with different event systems.
This makes it difficult to share your components with the community. Different event systems may conflict in the same namespace. It will only work in your own controlled environment. We want to make it easy to share and reuse components without conflicts.
So to support this we would need to build it in a way that supports isolation.
This is the major benefit of a wrapper like
<Tap />
since it does support component isolation by default.I think @sebmarkbage’s suggestion is valid: make a react component for the behavior and isolate it to that specific use case.