Material Components Web Docs - Auto Init
mdc-auto-init
is a utility package that provides declarative,
DOM-based method of initialization for MDC Web components on simple
web sites. Note that for more advanced use-cases and complex sites,
manual instantiation of components will give you more flexibility.
However, mdc-auto-init is great for static websites, prototypes, and
other use-cases where simplicity and convenience is most appropriate.
When mdc-auto-init
attaches a component to an element, it assign that instance to the element using a property whose name is the value of data-mdc-auto-init
. For example, given
<div class="mdc-text-field" data-mdc-auto-init="MDCTextField">
<input class="mdc-text-field__input" type="text" id="input">
<label for="input" class="mdc-floating-label">Input Label</label>
<div class="mdc-line-ripple"></div>
</div>
<!-- at the bottom of the page -->
<script type="text/javascript">
window.mdc.autoInit();
</script>
Once mdc.autoInit()
is called, you can access the component instance via an MDCTextField property on that element.