Skip to content

Commit 60b9ef9

Browse files
fix(routeToComponent): Do not prefix component element with x- unless necessary.
Closes #3394
1 parent 1b34e08 commit 60b9ef9

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/templateFactory.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ export class TemplateFactory implements TemplateFactoryProvider {
173173
};
174174

175175
let attrs = getComponentBindings(component).map(attributeTpl).join(" ");
176-
let kebobName = "x-" + kebobString(component);
176+
let kebobName = kebobString(component);
177+
if (/^(x|data)-/.exec(kebobName)) {
178+
kebobName = "x-" + kebobName;
179+
}
177180
return `<${kebobName} ${attrs}></${kebobName}>`;
178181
};
179182
}

test/templateFactorySpec.ts

+43
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as angular from "angular";
2+
import { UIRouter } from '@uirouter/core';
23

34
declare let inject;
45

@@ -83,4 +84,46 @@ describe('templateFactory', function () {
8384
$httpBackend.flush();
8485
}));
8586
});
87+
88+
if (angular.version.minor >= 5) {
89+
describe('component template builder', () => {
90+
let router: UIRouter, el, rootScope;
91+
let cmp = { template: 'hi' };
92+
93+
beforeEach(() => {
94+
let mod = angular.module('foo', []);
95+
mod.component('myComponent', cmp);
96+
mod.component('dataComponent', cmp);
97+
mod.component('xComponent', cmp);
98+
});
99+
beforeEach(module('foo'));
100+
101+
beforeEach(inject(($uiRouter, $compile, $rootScope) => {
102+
router = $uiRouter;
103+
rootScope = $rootScope;
104+
el = $compile(angular.element('<div><ui-view></ui-view></div>'))($rootScope.$new());
105+
}));
106+
107+
it('should not prefix the components dom element with anything', () => {
108+
router.stateRegistry.register({ name: 'cmp', component: 'myComponent' });
109+
router.stateService.go('cmp');
110+
rootScope.$digest();
111+
expect(el.html()).toMatch(/\<my-component/);
112+
});
113+
114+
it('should prefix the components dom element with x- for components named dataFoo', () => {
115+
router.stateRegistry.register({ name: 'cmp', component: 'dataComponent' });
116+
router.stateService.go('cmp');
117+
rootScope.$digest();
118+
expect(el.html()).toMatch(/\<x-data-component/);
119+
});
120+
121+
it('should prefix the components dom element with x- for components named xFoo', () => {
122+
router.stateRegistry.register({ name: 'cmp', component: 'xComponent' });
123+
router.stateService.go('cmp');
124+
rootScope.$digest();
125+
expect(el.html()).toMatch(/\<x-x-component/);
126+
})
127+
});
128+
}
86129
});

0 commit comments

Comments
 (0)