Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 6699ae6

Browse files
committed
fix(chips): placeholder is truncated even though there is room
- add a new `md-input-class` to `<md-chips>` to `md-chips` and `md-contact-chips` - allows custom styling like adding a `min-width` for supporting very long placeholders - this is the same API as `<md-autocomplete>` already has - add demo of long `placeholder` and `md-input-class` Fixes #10630
1 parent 01351b1 commit 6699ae6

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

src/components/chips/chips.scss

+15-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,15 @@ $contact-chip-name-width: rem(12) !default;
5151
.md-contact-chips-suggestions li {
5252
height: 100%;
5353
}
54+
md-chips {
55+
display: flex;
56+
}
5457
.md-chips {
5558
@include pie-clearfix();
5659

57-
display: block;
60+
display: flex;
61+
flex-wrap: wrap;
62+
flex-grow: 1;
5863
font-family: $font-family;
5964
font-size: $chip-font-size;
6065
@include rtl(padding, $chip-wrap-padding, rtl-value($chip-wrap-padding));
@@ -143,9 +148,17 @@ $contact-chip-name-width: rem(12) !default;
143148
line-height: $chip-height;
144149
@include rtl(margin, $chip-margin, rtl-value($chip-margin));
145150
padding: $chip-input-padding;
151+
flex-grow: 1;
146152
@include rtl(float, left, right);
147153
input {
148-
&:not([type]),&[type="email"],&[type="number"],&[type="tel"],&[type="url"],&[type="text"] {
154+
width: 100%;
155+
156+
&:not([type]),
157+
&[type="email"],
158+
&[type="number"],
159+
&[type="tel"],
160+
&[type="url"],
161+
&[type="text"] {
149162
border: 0;
150163
height: $chip-height;
151164
line-height: $chip-height;

src/components/chips/demoBasicUsage/index.html

+20-24
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
<div ng-controller="BasicDemoCtrl as ctrl" layout="column" ng-cloak>
22

33
<md-content class="md-padding" layout="column">
4-
<h2 class="md-title">Use a custom chip template.</h2>
5-
4+
<h2 class="md-title">Use the default chip template.</h2>
5+
<md-chips ng-model="ctrl.fruitNames" readonly="ctrl.readonly" md-removable="ctrl.removable">
6+
</md-chips>
7+
<br/>
8+
<h2 class="md-title">Use ng-change and add-on-blur</h2>
9+
<md-chips ng-model="ctrl.ngChangeFruitNames" md-add-on-blur="true" readonly="ctrl.readonly"
10+
ng-change="ctrl.onModelChange(ctrl.ngChangeFruitNames)" input-aria-label="Fruit names"
11+
md-removable="ctrl.removable"></md-chips>
12+
<br/>
13+
<h2 class="md-title">Make chips editable.</h2>
14+
<md-chips ng-model="ctrl.editableFruitNames" readonly="ctrl.readonly"
15+
md-removable="ctrl.removable" md-enable-chip-edit="true"
16+
input-aria-label="Fruit names"></md-chips>
17+
<br/>
18+
<h2 class="md-title">Use a custom chip template with max chips.</h2>
619
<form name="fruitForm">
720
<md-chips ng-model="ctrl.roFruitNames" name="fruitName" readonly="ctrl.readonly"
8-
md-removable="ctrl.removable" md-max-chips="5" placeholder="Enter a fruit..."
21+
md-removable="ctrl.removable" md-max-chips="5" placeholder="Ex. Peach"
922
input-aria-label="Fruit names">
1023
<md-chip-template>
1124
<strong>{{$chip}}</strong>
@@ -17,30 +30,14 @@ <h2 class="md-title">Use a custom chip template.</h2>
1730
<div ng-message="md-max-chips">Maximum number of chips reached.</div>
1831
</div>
1932
</form>
20-
2133
<br/>
22-
<h2 class="md-title">Use the default chip template.</h2>
23-
24-
<md-chips ng-model="ctrl.fruitNames" readonly="ctrl.readonly" md-removable="ctrl.removable">
34+
<h2 class="md-title">Use a long placeholder with md-input-class.</h2>
35+
<md-chips ng-model="ctrl.fruitNames" readonly="ctrl.readonly" md-removable="ctrl.removable"
36+
placeholder="Ex. Peach, Kiwi, Watermelon, Passion Fruit, Nectarine, etc."
37+
md-input-class="demo-long-fruit-input">
2538
</md-chips>
26-
27-
<br/>
28-
<h2 class="md-title">Use ng-change and add-on-blur</h2>
29-
30-
<md-chips ng-model="ctrl.ngChangeFruitNames" md-add-on-blur="true" readonly="ctrl.readonly"
31-
ng-change="ctrl.onModelChange(ctrl.ngChangeFruitNames)" input-aria-label="Fruit names"
32-
md-removable="ctrl.removable"></md-chips>
33-
34-
<br/>
35-
<h2 class="md-title">Make chips editable.</h2>
36-
37-
<md-chips ng-model="ctrl.editableFruitNames" readonly="ctrl.readonly"
38-
md-removable="ctrl.removable" md-enable-chip-edit="true"
39-
input-aria-label="Fruit names"></md-chips>
40-
4139
<br/>
4240
<h2 class="md-title">Use Placeholders and override hint texts.</h2>
43-
4441
<md-chips
4542
ng-model="ctrl.tags"
4643
readonly="ctrl.readonly"
@@ -55,7 +52,6 @@ <h2 class="md-title">Use Placeholders and override hint texts.</h2>
5552
container-hint="Chips container. Press the right and left arrow keys to change tag selection."
5653
container-empty-hint="Chips container. Enter the text area, start typing, and then press enter when done to add a tag.">
5754
</md-chips>
58-
5955
<br/>
6056
<h2 class="md-title">Display an ordered set of objects as chips (with custom template).</h2>
6157
<p>Note: the variables <code>$chip</code> and <code>$index</code> are available in custom chip templates.</p>

src/components/chips/demoBasicUsage/style.scss

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
color: rgb(221,44,0);
44
margin-top: 10px;
55
}
6+
.demo-long-fruit-input {
7+
min-width: 340px;
8+
}
69
.custom-chips {
710
md-chip {
811
position: relative;

src/components/chips/js/chipsController.js

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ function MdChipsCtrl ($scope, $attrs, $mdConstant, $log, $element, $timeout, $md
8181
/** @type {string} */
8282
this.addOnBlur = $mdUtil.parseAttributeBoolean($attrs.mdAddOnBlur);
8383

84+
/**
85+
* The class names to apply to the autocomplete or input.
86+
* @type {string}
87+
*/
88+
this.inputClass = '';
89+
8490
/**
8591
* The text to be used as the aria-label for the input.
8692
* @type {string}

src/components/chips/js/chipsDirective.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* <ul style="padding-left:20px;">
3434
*
3535
* <ul>Style
36-
* <li>Colours for hover, press states (ripple?).</li>
36+
* <li>Colors for hover, press states (ripple?).</li>
3737
* </ul>
3838
*
3939
* <ul>Validation
@@ -135,6 +135,9 @@
135135
* @param {expression=} md-on-select An expression which will be called when a chip is selected.
136136
* @param {boolean=} md-require-match If true, and the chips template contains an autocomplete,
137137
* only allow selection of pre-defined chips (i.e. you cannot add new ones).
138+
* @param {string=} md-input-class This class will be applied to the child input for custom
139+
* styling. If you are using an `md-autocomplete`, then you need to put this attribute on the
140+
* `md-autocomplete` rather than the `md-chips`.
138141
* @param {string=} input-aria-describedby A space-separated list of element IDs. This should
139142
* contain the IDs of any elements that describe this autocomplete. Screen readers will read
140143
* the content of these elements at the end of announcing that the chips input has been
@@ -249,7 +252,7 @@
249252

250253
var CHIP_INPUT_TEMPLATE = '\
251254
<input\
252-
class="md-input"\
255+
class="md-input{{ $mdChipsCtrl.inputClass ? \' \' + $mdChipsCtrl.inputClass: \'\'}}"\
253256
tabindex="0"\
254257
aria-label="{{$mdChipsCtrl.inputAriaLabel}}"\
255258
placeholder="{{$mdChipsCtrl.getPlaceholder()}}"\
@@ -306,6 +309,7 @@
306309
addedMessage: '@?mdAddedMessage',
307310
removedMessage: '@?mdRemovedMessage',
308311
onSelect: '&?mdOnSelect',
312+
inputClass: '@?mdInputClass',
309313
inputAriaDescribedBy: '@?inputAriaDescribedby',
310314
inputAriaLabelledBy: '@?inputAriaLabelledby',
311315
inputAriaLabel: '@?',

src/components/chips/js/contactChipsController.js

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ MdContactChipsCtrl.prototype.setupChipsAria = function() {
7171
if (this.inputAriaLabel) {
7272
chipsCtrl.inputAriaLabel = this.inputAriaLabel;
7373
}
74+
if (this.inputClass) {
75+
chipsCtrl.inputClass = this.inputClass;
76+
}
7477
};
7578

7679
MdContactChipsCtrl.prototype.setupAutocompleteAria = function() {

src/components/chips/js/contactChipsDirective.js

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ angular
3535
* contact's image.
3636
* @param {number=} md-min-length Specifies the minimum length of text before autocomplete will
3737
* make suggestions
38+
* @param {string=} md-input-class This class will be applied to the child `md-autocomplete` for
39+
* custom styling.
3840
* @param {string=} input-aria-describedby A space-separated list of element IDs. This should
3941
* contain the IDs of any elements that describe this autocomplete. Screen readers will read
4042
* the content of these elements at the end of announcing that the chips input has been
@@ -93,6 +95,7 @@ var MD_CONTACT_CHIPS_TEMPLATE = '\
9395
md-no-cache="true"\
9496
md-min-length="$mdContactChipsCtrl.minLength"\
9597
md-autoselect\
98+
ng-attr-md-input-class="{{$mdContactChipsCtrl.inputClass}}"\
9699
ng-keydown="$mdContactChipsCtrl.inputKeydown($event)"\
97100
placeholder="{{$mdContactChipsCtrl.contacts.length === 0 ?\
98101
$mdContactChipsCtrl.placeholder : $mdContactChipsCtrl.secondaryPlaceholder}}">\
@@ -155,6 +158,7 @@ function MdContactChips($mdTheming, $mdUtil) {
155158
chipAppendDelay: '@?mdChipAppendDelay',
156159
separatorKeys: '=?mdSeparatorKeys',
157160
removedMessage: '@?mdRemovedMessage',
161+
inputClass: '@?mdInputClass',
158162
inputAriaDescribedBy: '@?inputAriaDescribedby',
159163
inputAriaLabelledBy: '@?inputAriaLabelledby',
160164
inputAriaLabel: '@?',

0 commit comments

Comments
 (0)