admin管理员组文章数量:1404923
I use Material Design with my non-Node.js app. I need to use the Material outlined textfield (with leading icon) in my HTML project. Material.io website shows JavaScript code for some ponents but does not show it for others. How can I add the outlined textfield ponent in my HTML project?
Below is my code:
<html>
<head>
<link rel="stylesheet" href="@latest/dist/material-ponents-web.min.css" />
</head>
<body>
<!--button class="mdc-button mdc-button--raised">Button</button-->
<div class="mdc-text-field mdc-text-field--outlined">
<input type="text" id="tf-outlined" class="mdc-text-field__input" />
<label for="tf-outlined" class="mdc-floating-label">Your Name</label>
<div class="mdc-notched-outline">
<svg>
<path class="mdc-notched-outline__path"></path>
</svg>
</div>
<div class="mdc-notched-outline__idle"></div>
</div>
<script src="@latest/dist/material-ponents-web.min.js"></script>
</body>
</html>
A fiddle for this code: jsfiddle
I use Material Design with my non-Node.js app. I need to use the Material outlined textfield (with leading icon) in my HTML project. Material.io website shows JavaScript code for some ponents but does not show it for others. How can I add the outlined textfield ponent in my HTML project?
Below is my code:
<html>
<head>
<link rel="stylesheet" href="https://unpkg./material-ponents-web@latest/dist/material-ponents-web.min.css" />
</head>
<body>
<!--button class="mdc-button mdc-button--raised">Button</button-->
<div class="mdc-text-field mdc-text-field--outlined">
<input type="text" id="tf-outlined" class="mdc-text-field__input" />
<label for="tf-outlined" class="mdc-floating-label">Your Name</label>
<div class="mdc-notched-outline">
<svg>
<path class="mdc-notched-outline__path"></path>
</svg>
</div>
<div class="mdc-notched-outline__idle"></div>
</div>
<script src="https://unpkg./material-ponents-web@latest/dist/material-ponents-web.min.js"></script>
</body>
</html>
A fiddle for this code: jsfiddle
Share Improve this question edited Oct 19, 2018 at 13:14 benvc 15.2k4 gold badges38 silver badges57 bronze badges asked Jun 26, 2018 at 13:27 user9850863user9850863 1031 silver badge6 bronze badges2 Answers
Reset to default 8You really need to go through the documentation at mdc-textfield. Aside from the html fixes you will see below, be sure to notice the JavaScript that instantiates the textfield ponent (this is often what trips people up when they are trying to get started). You can also use mdc.autoInit()
with data-mdc-auto-init
markup to instantiate MDC ponents (see the Auto Init docs for details).
mdc.textField.MDCTextField.attachTo(document.querySelector('.mdc-text-field'));
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Material TextField Quick Start</title>
<link rel="stylesheet" href="https://fonts.googleapis./icon?family=Material+Icons">
<link rel="stylesheet" href="https://fonts.googleapis./css?family=Roboto:300,400,500,700">
<link href="https://unpkg./material-ponents-web@latest/dist/material-ponents-web.min.css" rel="stylesheet">
<script src="https://unpkg./material-ponents-web@latest/dist/material-ponents-web.min.js"></script>
</head>
<body>
<label class="mdc-text-field mdc-text-field--outlined mdc-text-field--with-leading-icon">
<i class="material-icons mdc-text-field__icon mdc-text-field__icon--leading" tabindex="0" role="button">event</i>
<input type="text" class="mdc-text-field__input">
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading"></span>
<span class="mdc-notched-outline__notch">
<span class="mdc-floating-label">Label</span>
</span>
<span class="mdc-notched-outline__trailing"></span>
</span>
</label>
</body>
</html>
The MDL Docs themselves have resources on how to include the ponents just using the standard <link>
and <script>
tags.
Docs: https://material.io/develop/web/docs/getting-started/
本文标签: javascriptHow to include Materialio outlined textfield in nonNodejs appStack Overflow
版权声明:本文标题:javascript - How to include Material.io outlined textfield in non-Node.js app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744878581a2630064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论