Skip to content

Commit de7f528

Browse files
committed
Fix wrong type component creation
1 parent 44fddff commit de7f528

7 files changed

Lines changed: 40 additions & 3 deletions

File tree

packages/cx-theme-aquamarine/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"cx": "*"
3333
},
3434
"devDependencies": {
35+
"cx": "workspace:*",
3536
"typescript": "^5.9.3"
3637
}
3738
}

packages/cx-theme-aquamarine/src/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@use "sass:map";
2-
@import "~cx/sass/index";
2+
@import "~cx/src/index";
33

44
$block: map.get($cx-besm, block);
55
$element: map.get($cx-besm, element);

packages/cx-theme-aquamarine/src/variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ $cx-default-progressbar-indicator-background-color: rgba($cx-theme-primary-color
284284
//list
285285
$cx-default-list-item-padding: 8px 12px !default;
286286

287-
@import "~cx/sass/variables";
287+
@import "~cx/src/variables";
288288

289289
//VARIABLE MAPS
290290
//LIST

packages/cx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cx",
3-
"version": "26.1.0",
3+
"version": "26.1.1",
44
"description": "Advanced JavaScript UI framework for admin and dashboard applications with ready to use grid, form and chart components.",
55
"exports": {
66
"./data": {

packages/cx/src/util/Component.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,36 @@ describe("Component.create", function () {
211211
});
212212
});
213213

214+
describe("type in second argument (more)", function () {
215+
it("should create instance of type specified in second argument", function () {
216+
const result = TestWidget.create({ text: "hello" }, { type: TestButton });
217+
assert.ok(result instanceof TestButton);
218+
assert.equal(result.text, "hello");
219+
});
220+
221+
it("should create instance of $type specified in second argument", function () {
222+
const result = TestWidget.create({ text: "world" }, { $type: TestButton });
223+
assert.ok(result instanceof TestButton);
224+
assert.equal(result.text, "world");
225+
});
226+
227+
it("should work when first argument is an array and second has type", function () {
228+
const results = Component.create([{ text: "A" }, { text: "B" }], { type: TestButton });
229+
assert.equal(results.length, 2);
230+
assert.ok(results[0] instanceof TestButton);
231+
assert.ok(results[1] instanceof TestButton);
232+
assert.equal(results[0].text, "A");
233+
assert.equal(results[1].text, "B");
234+
});
235+
236+
it("should work when type is passed as first arg with array config and type in more", function () {
237+
const results = Component.create(TestWidget, [{ text: "X" }], { type: TestButton });
238+
assert.equal(results.length, 1);
239+
assert.ok(results[0] instanceof TestButton);
240+
assert.equal(results[0].text, "X");
241+
});
242+
});
243+
214244
describe("heterogeneous array with type property", function () {
215245
it("creates array of different component types", function () {
216246
const results = Component.create([

packages/cx/src/util/Component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ export class Component {
268268

269269
if (more) cfg = Object.assign({}, config, more);
270270

271+
// Check if merged cfg has type/$type that should override cmpType
272+
// Only redirect if cfgType is a class (not a string alias or factory) to prevent infinite recursion
273+
let cfgType = cfg && (cfg.type || cfg.$type);
274+
if (cfgType && cfgType.isComponentType && cfgType !== cmpType) return this.create(cfg);
275+
271276
let cmp = new cmpType(cfg);
272277
if (cmpType.autoInit && cmp.init) cmp.init();
273278
return cmp;

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,6 +3981,7 @@ __metadata:
39813981
version: 0.0.0-use.local
39823982
resolution: "cx-theme-aquamarine@workspace:packages/cx-theme-aquamarine"
39833983
dependencies:
3984+
cx: "workspace:*"
39843985
typescript: "npm:^5.9.3"
39853986
peerDependencies:
39863987
cx: "*"

0 commit comments

Comments
 (0)