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

Commit 16486db

Browse files
fix(layouts): do not replace invalid attribute values
Do not modify attribute values with default/fallback values; only update the attrs hashmap with the fallback value. This allows components using matching directives to not lose the originating value. e.g. ```html < ui-layout layout="/api/sidebar.html" /> ``` will become ```html < ui-layout layout="/api/sidebar.html" class="layout-row" /> ```
1 parent 67ebee6 commit 16486db

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/core/services/layout/layout.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@
425425
function buildUpdateFn(element, className, attrs) {
426426
return function updateAttrValue(fallback) {
427427
if (!needsInterpolation(fallback)) {
428-
element.attr(className, fallback);
428+
// Do not modify the element's attribute value; so
429+
// uses '<ui-layout layout="/api/sidebar.html" />' will not
430+
// be affected. Just update the attrs value.
429431
attrs[attrs.$normalize(className)] = fallback;
430432
}
431433
};

src/core/services/layout/layout.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ describe('layout directives', function() {
2020

2121
it('should ignore invalid values', function() {
2222
var element = $compile('<div layout="humpty">Layout</div>')(pageScope);
23-
expect(element.hasClass("layout-row")).toBeTruthy();
23+
24+
expect( element.attr('layout') ).toBe('humpty'); // original attribute value unmodified
2425
expect(element.hasClass('layout-humpty')).toBeFalsy();
26+
expect(element.hasClass("layout-row")).toBeTruthy(); // injected className based on fallback value
2527
});
2628

2729
it('should support interpolated values layout-gt-sm="{{direction}}"', function() {
@@ -37,6 +39,7 @@ describe('layout directives', function() {
3739
expect(element.hasClass('layout-gt-sm-column')).toBeTruthy();
3840
});
3941

42+
4043
/**
4144
* For all breakpoints,
4245
* - Test percentage values

0 commit comments

Comments
 (0)