Skip to content

Commit

Permalink
Fix icons conflict (overrides each other) (#9094)
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 authored Nov 22, 2024
1 parent 165a6d2 commit 59b4420
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions packages/survey-core/src/svgbundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export class SvgIconRegistry {
private iconPrefix = "icon-";

private processId(iconId: string, iconPrefix: string) {
if (iconId.indexOf(iconPrefix) == 0) iconId = iconId.substring(iconPrefix.length);
iconId = renamedIcons[iconId] || iconId;
if (iconId.indexOf(iconPrefix) == 0) {
iconId = iconId.substring(iconPrefix.length);
}
return iconId;
}
public registerIconFromSymbol(iconId: string, iconSymbolSvg: string) {
Expand Down
38 changes: 19 additions & 19 deletions packages/survey-core/tests/icons/svgRegistryTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@ QUnit.test("svg import from svg via string - use prefix", function (assert) {
assert.equal(svg.iconsRenderedHtml(), "<symbol id=\"icon-a\" viewBox=\"0 0 100 100\"><circle/></symbol>");
});

QUnit.test("check that user's svgs with old name will be supported after icons renaming", function (assert) {
const oldIconName = "icon-changecamera"; // see renamedIcons dictionary
const newIconName = "icon-flip-24x24";

let svg = new SvgIconRegistry();
let res = svg.registerIconFromSvg(oldIconName, "<svg viewBox=\"0 0 100 100\"><circle/></svg>");
assert.ok(res);
assert.equal(svg.iconsRenderedHtml(), `<symbol id="${newIconName}" viewBox="0 0 100 100"><circle/></symbol>`);
});

QUnit.test("check that user's svgs with old name will be supported after icons renaming: whithout 'icon-' prefix", function (assert) {
const oldIconName = "changecamera"; // see renamedIcons dictionary
const newIconName = "flip-24x24";

let svg = new SvgIconRegistry();
let res = svg.registerIconFromSvg(oldIconName, "<svg viewBox=\"0 0 100 100\"><circle/></svg>");
assert.ok(res);
assert.equal(svg.iconsRenderedHtml(), `<symbol id="icon-${newIconName}" viewBox="0 0 100 100"><circle/></symbol>`);
});
// QUnit.test("check that user's svgs with old name will be supported after icons renaming", function (assert) {
// const oldIconName = "icon-changecamera"; // see renamedIcons dictionary
// const newIconName = "icon-flip-24x24";

// let svg = new SvgIconRegistry();
// let res = svg.registerIconFromSvg(oldIconName, "<svg viewBox=\"0 0 100 100\"><circle/></svg>");
// assert.ok(res);
// assert.equal(svg.iconsRenderedHtml(), `<symbol id="${newIconName}" viewBox="0 0 100 100"><circle/></symbol>`);
// });

// QUnit.test("check that user's svgs with old name will be supported after icons renaming: whithout 'icon-' prefix", function (assert) {
// const oldIconName = "changecamera"; // see renamedIcons dictionary
// const newIconName = "flip-24x24";

// let svg = new SvgIconRegistry();
// let res = svg.registerIconFromSvg(oldIconName, "<svg viewBox=\"0 0 100 100\"><circle/></svg>");
// assert.ok(res);
// assert.equal(svg.iconsRenderedHtml(), `<symbol id="icon-${newIconName}" viewBox="0 0 100 100"><circle/></symbol>`);
// });

0 comments on commit 59b4420

Please sign in to comment.