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

Commit b8bd4d5

Browse files
davidchangmhevery
authored andcommitted
feat(directive): added ng-open boolean directive
Closes# 1797 add ng-open attribute
1 parent b2f4625 commit b8bd4d5

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/jqLite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,11 @@ var JQLitePrototype = JQLite.prototype = {
353353
// value on get.
354354
//////////////////////////////////////////
355355
var BOOLEAN_ATTR = {};
356-
forEach('multiple,selected,checked,disabled,readOnly,required'.split(','), function(value) {
356+
forEach('multiple,selected,checked,disabled,readOnly,required,open'.split(','), function(value) {
357357
BOOLEAN_ATTR[lowercase(value)] = value;
358358
});
359359
var BOOLEAN_ELEMENTS = {};
360-
forEach('input,select,option,textarea,button,form'.split(','), function(value) {
360+
forEach('input,select,option,textarea,button,form,details'.split(','), function(value) {
361361
BOOLEAN_ELEMENTS[uppercase(value)] = true;
362362
});
363363

src/ng/directive/booleanAttrs.js

+31
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,37 @@
272272
* @param {string} expression Angular expression that will be evaluated.
273273
*/
274274

275+
/**
276+
* @ngdoc directive
277+
* @name ng.directive:ngOpen
278+
* @restrict A
279+
*
280+
* @description
281+
* The HTML specs do not require browsers to preserve the special attributes such as open.
282+
* (The presence of them means true and absence means false)
283+
* This prevents the angular compiler from correctly retrieving the binding expression.
284+
* To solve this problem, we introduce the `ngMultiple` directive.
285+
*
286+
* @example
287+
<doc:example>
288+
<doc:source>
289+
Check me check multiple: <input type="checkbox" ng-model="open"><br/>
290+
<details id="details" ng-open="open">
291+
<summary>Show/Hide me</summary>
292+
</details>
293+
</doc:source>
294+
<doc:scenario>
295+
it('should toggle open', function() {
296+
expect(element('#details').prop('open')).toBeFalsy();
297+
input('open').check();
298+
expect(element('#details').prop('open')).toBeTruthy();
299+
});
300+
</doc:scenario>
301+
</doc:example>
302+
*
303+
* @element DETAILS
304+
* @param {string} expression Angular expression that will be evaluated.
305+
*/
275306

276307
var ngAttributeAliasDirectives = {};
277308

test/ng/directive/booleanAttrsSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ describe('boolean attr directives', function() {
7474
$rootScope.$digest();
7575
expect(element.attr('multiple')).toBeTruthy();
7676
}));
77+
78+
it('should bind open', inject(function($rootScope, $compile) {
79+
element = $compile('<details ng-open="isOpen"></details>')($rootScope)
80+
$rootScope.isOpen=false;
81+
$rootScope.$digest();
82+
expect(element.attr('open')).toBeFalsy();
83+
$rootScope.isOpen=true;
84+
$rootScope.$digest();
85+
expect(element.attr('open')).toBeTruthy();
86+
}));
7787
});
7888

7989

0 commit comments

Comments
 (0)