Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Web Components be used to create custom input elements?

How is it/(or just "is it?") possible to create a Web Component that can be placed inside a form and act just as any input element, that's sent to the server on submit? In other words, can Web Components be used to create custom input elements?

like image 297
Lars C. Magnusson Avatar asked Sep 04 '13 21:09

Lars C. Magnusson


People also ask

What are Web Components used for?

Web Components is a suite of different technologies allowing you to create reusable custom elements — with their functionality encapsulated away from the rest of your code — and utilize them in your web apps.

Which way is used to create a custom element?

Customized built-in elements inherit from basic HTML elements. To create one of these, you have to specify which element they extend (as implied in the examples above), and they are used by writing out the basic element but specifying the name of the custom element in the is attribute (or property).

Can we create own custom component?

The Android UI model is inherently customizable, offering the means of Android customization, testing, and the ability to create custom UI components in various ways: Inherit an existing component (i.e. TextView , ImageView , etc.), and add/override needed functionality.

What is custom element in LWC?

Lightning Web Component or LWC are custom elements built using native HTML and Modern JavaScript. It uses core web components standards and latest ECMAScript 6, 7, 8, 9 and beyond. Salesforce provides an open library known as Lightning Web Component Open Source, which can implemented in any platform.


1 Answers

Use the following browser configuration options before testing:

  • Chrome: about:flags => Enabled Experimental WebKit Features/Enable Experimental Web Platform
  • Firefox: about:config => dom.registercomponents.enabled

to enable document.registerElement.

Use the extends parameter of document.registerElement to extend a native input element:

/* Cross-browser fallback */
document.registerElement = document.registerElement || document.register;
/* Element registration using x-tag format */
var MegaButton = document.registerElement('x-button', {
  prototype: Object.create(HTMLButtonElement.prototype),
  extends: 'button'
  });

References

  • Extending Native Elements
  • HTML as Custom Elements
  • Extending Custom Elements
  • Create Custom HTML Elements
  • x-tag and the Web Components Family
  • Performance and Custom Elements
  • Mozilla: Custom Elements
  • Detailed Introduction to Custom Elements
  • Web Components: The Chromium Projects
  • Web Components Best Practices
  • Component Model Wiki
  • Web Component Proposals: Type Extensions
like image 78
Paul Sweatte Avatar answered Sep 23 '22 15:09

Paul Sweatte