question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I extend HTML element

See original GitHub issue

For 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:closed
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sebmarkbagecommented, May 13, 2015

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.

0reactions
nhunzakercommented, Jul 12, 2017

I think @sebmarkbage’s suggestion is valid: make a react component for the behavior and isolate it to that specific use case.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found