So I am using MDC (Material design components) without node.js, meaning I have to import it like this:
<link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
So the CSS works fine, I can use any class from the MDC and it works flawlessly.
But there is some partial problem with the JavaScript additional effects. The TextField works fine - when I click it, the text shifts. But any other JS effect is not working.
<label class="mdc-text-field mdc-text-field--outlined">
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading"></span>
<span class="mdc-notched-outline__notch">
<span class="mdc-floating-label" id="my-label-id">OpenWeatherMap API key</span>
</span>
<span class="mdc-notched-outline__trailing"></span>
</span>
<input type="text" class="mdc-text-field__input" aria-labelledby="my-label-id" style="width: 512px;">
</label>
<br>
<button class="mdc-button mdc-button--raised">
<span class="mdc-button__label">Grant location permision</span>
</button>
<script>
mdc.ripple.MDCRipple.attachTo(document.querySelector('.mdc-button')); <!-- This does not work>
mdc.textField.MDCTextField.attachTo(document.querySelector('.mdc-text-field')); <!-- This works fine>
</script>
Does anybody know how to fix this? I tried everything I found.
You need to add mdc-button__ripple
element inside button:
<button class="mdc-button mdc-button--raised">
<span class="mdc-button__ripple"></span>
<span class="mdc-button__label">Grant location permision</span>
</button>