This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(text-field): Split out icon into subelement (#1697)
BREAKING CHANGE: Remove `setIconAttr`, `eventTargetHasClass` and `notifyIconAction` from `MDCTextFieldAdapter` implementations.
- Loading branch information
1 parent
7c68674
commit 4e7fa3e
Showing
16 changed files
with
647 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<!--docs: | ||
title: "Text Field Icon" | ||
layout: detail | ||
section: components | ||
excerpt: "Icons describe the type of input a text field requires" | ||
iconId: text_field | ||
path: /catalog/input-controls/text-fields/icon/ | ||
--> | ||
|
||
# Text Field Icon | ||
|
||
Icons describe the type of input a text field requires. They can also be interaction targets. | ||
|
||
## Design & API Documentation | ||
|
||
<ul class="icon-list"> | ||
<li class="icon-list-item icon-list-item--spec"> | ||
<a href="https://material.io/guidelines/components/text-fields.html#text-fields-layout">Material Design guidelines: Text Fields Layout</a> | ||
</li> | ||
</ul> | ||
|
||
## Usage | ||
|
||
### Leading and Trailing Icons | ||
Leading and trailing icons can be added to MDC Text Fields as visual indicators | ||
as well as interaction targets. To do so, add the relevant classes | ||
(`mdc-text-field--with-leading-icon` or `mdc-text-field--with-trailing-icon`) to the root element, add | ||
an `i` element with your preferred icon, and give it a class of `mdc-text-field__icon`. | ||
|
||
#### Leading: | ||
```html | ||
<div class="mdc-text-field mdc-text-field--box mdc-text-field--with-leading-icon"> | ||
<i class="material-icons mdc-text-field__icon" tabindex="0">event</i> | ||
<input type="text" id="my-input" class="mdc-text-field__input"> | ||
<label for="my-input" class="mdc-text-field__label">Your Name</label> | ||
<div class="mdc-text-field__bottom-line"></div> | ||
</div> | ||
``` | ||
|
||
#### Trailing: | ||
```html | ||
<div class="mdc-text-field mdc-text-field--box mdc-text-field--with-trailing-icon"> | ||
<input type="text" id="my-input" class="mdc-text-field__input"> | ||
<label for="my-input" class="mdc-text-field__label">Your Name</label> | ||
<i class="material-icons mdc-text-field__icon" tabindex="0">event</i> | ||
<div class="mdc-text-field__bottom-line"></div> | ||
</div> | ||
``` | ||
|
||
>**NOTE:** if you would like to display un-clickable icons, simply remove `tabindex="0"`, | ||
and the css will ensure the cursor is set to default, and that actioning on an icon doesn't | ||
do anything unexpected. | ||
|
||
#### MDCTextFieldIcon API | ||
|
||
##### MDCTextFieldIcon.foundation | ||
|
||
MDCTextFieldIconFoundation. This allows the parent MDCTextField component to access the public methods on the MDCTextFieldIconFoundation class. | ||
|
||
### Using the foundation class | ||
|
||
Method Signature | Description | ||
--- | --- | ||
setAttr(attr: string, value: string) => void | Sets an attribute with a given value on the icon element | ||
registerInteractionHandler(evtType: string, handler: EventListener) => void | Registers an event listener for a given event | ||
deregisterInteractionHandler(evtType: string, handler: EventListener) => void | Deregisters an event listener for a given event | ||
notifyIconAction() => void | Emits a custom event "MDCTextField:icon" denoting a user has clicked the icon, which bubbles to the top-level text field element | ||
|
||
#### The full foundation API | ||
|
||
##### MDCTextFieldIconFoundation.setDisabled(disabled: boolean) | ||
|
||
Updates the icon's disabled state. | ||
|
||
##### MDCTextFieldIconFoundation.handleInteraction(evt: Event) | ||
|
||
Handles a text field interaction event. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @license | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* eslint no-unused-vars: [2, {"args": "none"}] */ | ||
|
||
/** | ||
* Adapter for MDC Text Field Icon. | ||
* | ||
* Defines the shape of the adapter expected by the foundation. Implement this | ||
* adapter to integrate the text field icon into your framework. See | ||
* https://github.com/material-components/material-components-web/blob/master/docs/authoring-components.md | ||
* for more information. | ||
* | ||
* @record | ||
*/ | ||
class MDCTextFieldIconAdapter { | ||
/** | ||
* Sets an attribute on the icon element. | ||
* @param {string} attr | ||
* @param {string} value | ||
*/ | ||
setAttr(attr, value) {} | ||
|
||
/** | ||
* Registers an event listener on the icon element for a given event. | ||
* @param {string} evtType | ||
* @param {function(!Event): undefined} handler | ||
*/ | ||
registerInteractionHandler(evtType, handler) {} | ||
|
||
/** | ||
* Deregisters an event listener on the icon element for a given event. | ||
* @param {string} evtType | ||
* @param {function(!Event): undefined} handler | ||
*/ | ||
deregisterInteractionHandler(evtType, handler) {} | ||
|
||
/** | ||
* Emits a custom event "MDCTextField:icon" denoting a user has clicked the icon. | ||
*/ | ||
notifyIconAction() {} | ||
} | ||
|
||
export default MDCTextFieldIconAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @license | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** @enum {string} */ | ||
const strings = { | ||
ICON_EVENT: 'MDCTextField:icon', | ||
}; | ||
|
||
export {strings}; |
Oops, something went wrong.