Currently, I am utilizing Material Design WEB components in my project.
Below are the CSS and JS files that have been included:
<head>
<link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
</head>
In a separate JS file, I have attempted to:
const textField = document.querySelector('.mdc-text-field');
mdc.textField.MDCTextField.attachTo(textField);
const button = document.querySelector(".mdc-button");
mdc.ripple.MDCRipple.attachTo(button);
const formField = document.querySelector('.mdc-form-field');
const checkbox = document.querySelector('.mdc-checkbox');
mdc.formField.input= checkbox;
The issue I am facing is that when there are two text boxes in the HTML, it only works for the first element and not for others. Additionally, the checkbox functionality is not working at all.
<label class="mdc-text-field mdc-text-field--outlined">
<input type="text" class="mdc-text-field__input" asp-for="Username" autofocus aria-labelledby="user name">
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading"></span>
<span class="mdc-notched-outline__notch">
<span class="mdc-floating-label" asp-for="Username">User Name</span>
</span>
<span class="mdc-notched-outline__trailing"></span>
</span>
</label>
<label class="mdc-text-field mdc-text-field--outlined">
<input type="password" class="mdc-text-field__input" asp-for="Password" aria-labelledby="password">
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading"></span>
<span class="mdc-notched-outline__notch">
<span class="mdc-floating-label" asp-for="Password" autocomplete="off">Password</span>
</span>
<span class="mdc-notched-outline__trailing"></span>
</span>
</label>
If you want to check out an image of the issue, click here.
I am looking for guidance on where I can find a list detailing how to instantiate JavaScript like this:
mdc.ripple.MDCRipple.attachTo(document.querySelector('.foo-button'));