From 16486dbf84191e754bf57a357bded336a8215ce4 Mon Sep 17 00:00:00 2001 From: Thomas Burleson Date: Fri, 11 Dec 2015 17:30:18 -0600 Subject: [PATCH] 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" /> ``` --- src/core/services/layout/layout.js | 4 +++- src/core/services/layout/layout.spec.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/services/layout/layout.js b/src/core/services/layout/layout.js index 55b14762862..f9a8df37334 100644 --- a/src/core/services/layout/layout.js +++ b/src/core/services/layout/layout.js @@ -425,7 +425,9 @@ function buildUpdateFn(element, className, attrs) { return function updateAttrValue(fallback) { if (!needsInterpolation(fallback)) { - element.attr(className, fallback); + // Do not modify the element's attribute value; so + // uses '' will not + // be affected. Just update the attrs value. attrs[attrs.$normalize(className)] = fallback; } }; diff --git a/src/core/services/layout/layout.spec.js b/src/core/services/layout/layout.spec.js index aee01b23a42..60760a73903 100644 --- a/src/core/services/layout/layout.spec.js +++ b/src/core/services/layout/layout.spec.js @@ -20,8 +20,10 @@ describe('layout directives', function() { it('should ignore invalid values', function() { var element = $compile('
Layout
')(pageScope); - expect(element.hasClass("layout-row")).toBeTruthy(); + + expect( element.attr('layout') ).toBe('humpty'); // original attribute value unmodified expect(element.hasClass('layout-humpty')).toBeFalsy(); + expect(element.hasClass("layout-row")).toBeTruthy(); // injected className based on fallback value }); it('should support interpolated values layout-gt-sm="{{direction}}"', function() { @@ -37,6 +39,7 @@ describe('layout directives', function() { expect(element.hasClass('layout-gt-sm-column')).toBeTruthy(); }); + /** * For all breakpoints, * - Test percentage values