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

Commit 00474c3

Browse files
topherfangioThomasBurleson
authored andcommitted
feat(contactChips): Add md-highlight-flags support.
Contact Chips currently allows the use of `md-highlight-text` to match the search text. Users have requested we add `md-highlight-flags` as well so that the highlighted text can match the search field parameters. Mainly, if a match is found with case-insensitive search, it would be nice if the highlight text was also case-insensitive. fixes #3182. closes #4278.
1 parent 27ea0c9 commit 00474c3

File tree

3 files changed

+127
-106
lines changed

3 files changed

+127
-106
lines changed

src/components/chips/contact-chips.spec.js

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('<md-contact-chips>', function() {
77
md-contact-name="name"\
88
md-contact-image="image"\
99
md-contact-email="email"\
10+
md-highlight-flags="i"\
1011
placeholder="To">\
1112
</md-contact-chips>';
1213

@@ -31,6 +32,8 @@ describe('<md-contact-chips>', function() {
3132
}
3233
];
3334
scope.contacts = [];
35+
36+
scope.highlightFlags = "i";
3437
}));
3538

3639
var attachedElements = [];
@@ -42,26 +45,34 @@ describe('<md-contact-chips>', function() {
4245
});
4346

4447
describe('basic functionality', function() {
45-
it('should show the placeholder', inject(function($timeout) {
48+
it('should show the placeholder', inject(function() {
4649
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
4750
var ctrl = element.controller('mdContactChips');
48-
$timeout.flush();
51+
4952
expect(element.find('input').length).toBe(1);
5053
expect(element.find('input')[0].placeholder).toBe('To');
5154
}));
5255

56+
it('binds the md-highlight-flags to the controller', function() {
57+
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
58+
var ctrl = element.controller('mdContactChips');
59+
60+
expect(ctrl.highlightFlags).toEqual('i');
61+
});
62+
5363
describe('filtering selected items', function() {
54-
it('should filter', inject(function($timeout) {
64+
it('should filter', inject(function() {
5565
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {
5666
return scope.allContacts;
5767
});
5868
scope.contacts.push(scope.allContacts[2]);
69+
5970
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
6071
var ctrl = element.controller('mdContactChips');
61-
$timeout.flush();
6272

6373
var autocompleteElement = element.find('md-autocomplete');
6474
var autocompleteCtrl = autocompleteElement.controller('mdAutocomplete');
75+
6576
element.scope().$apply(function() {
6677
autocompleteCtrl.scope.searchText = 'NAME';
6778
autocompleteCtrl.keydown({});
@@ -72,25 +83,25 @@ describe('<md-contact-chips>', function() {
7283
}));
7384

7485
/* it('should not filter when disabled', inject(function($timeout) {
75-
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {
76-
return scope.allContacts;
77-
});
78-
scope.contacts.push(scope.allContacts[2]);
79-
scope.filterSelected = false;
80-
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
81-
var ctrl = element.controller('mdContactChips');
82-
$timeout.flush();
86+
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {
87+
return scope.allContacts;
88+
});
89+
scope.contacts.push(scope.allContacts[2]);
90+
scope.filterSelected = false;
91+
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
92+
var ctrl = element.controller('mdContactChips');
93+
$timeout.flush();
8394
84-
var autocompleteElement = element.find('md-autocomplete');
85-
var autocompleteCtrl = autocompleteElement.controller('mdAutocomplete');
86-
element.scope().$apply(function() {
87-
autocompleteCtrl.scope.searchText = 'NAME';
88-
autocompleteCtrl.keydown({});
89-
});
95+
var autocompleteElement = element.find('md-autocomplete');
96+
var autocompleteCtrl = autocompleteElement.controller('mdAutocomplete');
97+
element.scope().$apply(function() {
98+
autocompleteCtrl.scope.searchText = 'NAME';
99+
autocompleteCtrl.keydown({});
100+
});
90101
91-
var matches = autocompleteCtrl.matches;
92-
expect(matches.length).toBe(3);
93-
}));*/
102+
var matches = autocompleteCtrl.matches;
103+
expect(matches.length).toBe(3);
104+
}));*/
94105
});
95106

96107
});
@@ -101,11 +112,15 @@ describe('<md-contact-chips>', function() {
101112

102113
function buildChips(str) {
103114
var container;
104-
inject(function($compile) {
115+
116+
inject(function($compile, $timeout) {
105117
container = $compile(str)(scope);
106118
container.scope().$apply();
119+
$timeout.flush();
107120
});
121+
108122
attachedElements.push(container);
123+
109124
return container;
110125
}
111126

src/components/chips/demoContactChips/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
md-contact-image="image"
99
md-contact-email="email"
1010
md-require-match="true"
11+
md-highlight-flags="i"
1112
filter-selected="ctrl.filterSelected"
1213
placeholder="To">
1314
</md-contact-chips>
Lines changed: 89 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,57 @@
1-
angular
2-
.module('material.components.chips')
3-
.directive('mdContactChips', MdContactChips);
1+
angular
2+
.module('material.components.chips')
3+
.directive('mdContactChips', MdContactChips);
44

5-
/**
6-
* @ngdoc directive
7-
* @name mdContactChips
8-
* @module material.components.chips
9-
*
10-
* @description
11-
* `<md-contact-chips>` is an input component based on `md-chips` and makes use of an
12-
* `md-autocomplete` element. The component allows the caller to supply a query expression
13-
* which returns a list of possible contacts. The user can select one of these and add it to
14-
* the list of chips.
15-
*
16-
* @param {string=|object=} ng-model A model to bind the list of items to
17-
* @param {string=} placeholder Placeholder text that will be forwarded to the input.
18-
* @param {string=} secondary-placeholder Placeholder text that will be forwarded to the input,
19-
* displayed when there is at least on item in the list
20-
* @param {expression} md-contacts An expression expected to return contacts matching the search
21-
* test, `$query`.
22-
* @param {string} md-contact-name The field name of the contact object representing the
23-
* contact's name.
24-
* @param {string} md-contact-email The field name of the contact object representing the
25-
* contact's email address.
26-
* @param {string} md-contact-image The field name of the contact object representing the
27-
* contact's image.
28-
*
29-
*
30-
* // The following attribute has been removed but may come back.
31-
* @param {expression=} filter-selected Whether to filter selected contacts from the list of
32-
* suggestions shown in the autocomplete.
33-
*
34-
*
35-
*
36-
* @usage
37-
* <hljs lang="html">
38-
* <md-contact-chips
39-
* ng-model="ctrl.contacts"
40-
* md-contacts="ctrl.querySearch($query)"
41-
* md-contact-name="name"
42-
* md-contact-image="image"
43-
* md-contact-email="email"
44-
* placeholder="To">
45-
* </md-contact-chips>
46-
* </hljs>
47-
*
48-
*/
5+
/**
6+
* @ngdoc directive
7+
* @name mdContactChips
8+
* @module material.components.chips
9+
*
10+
* @description
11+
* `<md-contact-chips>` is an input component based on `md-chips` and makes use of an
12+
* `md-autocomplete` element. The component allows the caller to supply a query expression which
13+
* returns a list of possible contacts. The user can select one of these and add it to the list of
14+
* chips.
15+
*
16+
* You may also use the `md-highlight-text` directive along with it's parameters to control the
17+
* appearance of the matched text inside of the contacts' autocomplete popup.
18+
*
19+
* @param {string=|object=} ng-model A model to bind the list of items to
20+
* @param {string=} placeholder Placeholder text that will be forwarded to the input.
21+
* @param {string=} secondary-placeholder Placeholder text that will be forwarded to the input,
22+
* displayed when there is at least on item in the list
23+
* @param {expression} md-contacts An expression expected to return contacts matching the search
24+
* test, `$query`.
25+
* @param {string} md-contact-name The field name of the contact object representing the
26+
* contact's name.
27+
* @param {string} md-contact-email The field name of the contact object representing the
28+
* contact's email address.
29+
* @param {string} md-contact-image The field name of the contact object representing the
30+
* contact's image.
31+
*
32+
*
33+
* // The following attribute has been removed but may come back.
34+
* @param {expression=} filter-selected Whether to filter selected contacts from the list of
35+
* suggestions shown in the autocomplete.
36+
*
37+
*
38+
*
39+
* @usage
40+
* <hljs lang="html">
41+
* <md-contact-chips
42+
* ng-model="ctrl.contacts"
43+
* md-contacts="ctrl.querySearch($query)"
44+
* md-contact-name="name"
45+
* md-contact-image="image"
46+
* md-contact-email="email"
47+
* placeholder="To">
48+
* </md-contact-chips>
49+
* </hljs>
50+
*
51+
*/
4952

5053

51-
var MD_CONTACT_CHIPS_TEMPLATE = '\
54+
var MD_CONTACT_CHIPS_TEMPLATE = '\
5255
<md-chips class="md-contact-chips"\
5356
ng-model="$mdContactChipsCtrl.contacts"\
5457
md-require-match="$mdContactChipsCtrl.requireMatch"\
@@ -67,7 +70,8 @@
6770
<img \
6871
ng-src="{{item[$mdContactChipsCtrl.contactImage]}}"\
6972
alt="{{item[$mdContactChipsCtrl.contactName]}}" />\
70-
<span class="md-contact-name" md-highlight-text="$mdContactChipsCtrl.searchText">\
73+
<span class="md-contact-name" md-highlight-text="$mdContactChipsCtrl.searchText"\
74+
md-highlight-flags="{{$mdContactChipsCtrl.highlightFlags}}">\
7175
{{item[$mdContactChipsCtrl.contactName]}}\
7276
</span>\
7377
<span class="md-contact-email" >{{item[$mdContactChipsCtrl.contactEmail]}}</span>\
@@ -86,42 +90,43 @@
8690
</md-chips>';
8791

8892

89-
/**
90-
* MDContactChips Directive Definition
91-
*
92-
* @param $mdTheming
93-
* @returns {*}
94-
* @ngInject
95-
*/
96-
function MdContactChips ($mdTheming, $mdUtil) {
97-
return {
98-
template: function(element, attrs) {
99-
return MD_CONTACT_CHIPS_TEMPLATE;
100-
},
101-
restrict: 'E',
102-
controller: 'MdContactChipsCtrl',
103-
controllerAs: '$mdContactChipsCtrl',
104-
bindToController: true,
105-
compile: compile,
106-
scope: {
107-
contactQuery: '&mdContacts',
108-
placeholder: '@',
109-
secondaryPlaceholder: '@',
110-
contactName: '@mdContactName',
111-
contactImage: '@mdContactImage',
112-
contactEmail: '@mdContactEmail',
113-
contacts: '=ngModel',
114-
requireMatch: '=?mdRequireMatch'
115-
}
116-
};
93+
/**
94+
* MDContactChips Directive Definition
95+
*
96+
* @param $mdTheming
97+
* @returns {*}
98+
* @ngInject
99+
*/
100+
function MdContactChips($mdTheming, $mdUtil) {
101+
return {
102+
template: function(element, attrs) {
103+
return MD_CONTACT_CHIPS_TEMPLATE;
104+
},
105+
restrict: 'E',
106+
controller: 'MdContactChipsCtrl',
107+
controllerAs: '$mdContactChipsCtrl',
108+
bindToController: true,
109+
compile: compile,
110+
scope: {
111+
contactQuery: '&mdContacts',
112+
placeholder: '@',
113+
secondaryPlaceholder: '@',
114+
contactName: '@mdContactName',
115+
contactImage: '@mdContactImage',
116+
contactEmail: '@mdContactEmail',
117+
contacts: '=ngModel',
118+
requireMatch: '=?mdRequireMatch',
119+
highlightFlags: '@?mdHighlightFlags'
120+
}
121+
};
117122

118-
function compile(element, attr) {
119-
return function postLink(scope, element, attrs, controllers) {
123+
function compile(element, attr) {
124+
return function postLink(scope, element, attrs, controllers) {
120125

121-
$mdUtil.initOptionalProperties(scope, attr);
122-
$mdTheming(element);
126+
$mdUtil.initOptionalProperties(scope, attr);
127+
$mdTheming(element);
123128

124-
element.attr('tabindex', '-1');
125-
};
126-
}
129+
element.attr('tabindex', '-1');
130+
};
127131
}
132+
}

0 commit comments

Comments
 (0)