Skip to content

Commit f482a75

Browse files
committed
fix: remove defensive coding
1 parent 078629a commit f482a75

File tree

3 files changed

+7
-71
lines changed

3 files changed

+7
-71
lines changed

src/auro-tail-group.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import AuroLibraryRuntimeUtils from "@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs";
22
import { LitElement, html, nothing } from 'lit';
3-
import { MAX_TAILS_IN_GROUP, GROUPS_SIZES } from './constants';
3+
import { GROUPS_SIZES } from './constants';
44
import groupStyleCss from './styles/auro-tail-group.scss';
55

66
/**
@@ -69,17 +69,6 @@ export class AuroTailGroup extends LitElement {
6969
this.runtimeUtils = new AuroLibraryRuntimeUtils();
7070
}
7171

72-
/**
73-
* Prevent shadow DOM creation for unsupported sizes.
74-
* @protected
75-
*/
76-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
77-
createRenderRoot() {
78-
if (!GROUPS_SIZES.includes(this.size)) {
79-
return this;
80-
}
81-
return super.createRenderRoot();
82-
}
8372

8473
connectedCallback() {
8574
super.connectedCallback();
@@ -102,31 +91,21 @@ export class AuroTailGroup extends LitElement {
10291
}
10392

10493
/**
105-
* Manages child tails - removes excess tails and updates sizes.
94+
* Updates the size of child tails to match the group size.
10695
* @private
10796
*/
10897
updateChildTails() {
10998
// Small delay to ensure slotted content is available
11099
setTimeout(() => {
111-
const allChildren = Array.from(this.children);
112-
const tails = allChildren.filter(isAuroTailElement);
113-
114-
// If size is not supported, remove all child tails from light DOM.
115100
if (!GROUPS_SIZES.includes(this.size)) {
116-
tails.forEach((tail) => {
117-
tail.remove();
118-
});
119101
return;
120102
}
121103

122-
// Remove excess tails from DOM completely.
123-
tails.forEach((tail, index) => {
124-
if (index >= MAX_TAILS_IN_GROUP) {
125-
tail.remove();
126-
} else {
127-
// Update size for allowed tails
128-
tail.size = this.size;
129-
}
104+
const allChildren = Array.from(this.children);
105+
const tails = allChildren.filter(isAuroTailElement);
106+
107+
tails.forEach((tail) => {
108+
tail.size = this.size;
130109
});
131110
}, 0);
132111
}

src/constants.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ export const BADGES_SIZES = ['md', 'lg', 'xl', '2xl'];
1616
// Sizes that should be used in groups
1717
export const GROUPS_SIZES = ['xs', 'sm', 'md', 'lg'];
1818

19-
// Maximum number of tails allowed in a group
20-
export const MAX_TAILS_IN_GROUP = 2;
21-
2219
// Default airline name (EN/i18n)
2320
export const DEFAULT_AIRLINE_NAME = 'Airline';
2421

test/auro-tail-group.test.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,46 +66,6 @@ describe("auro-tail-group", () => {
6666
expect(tails[0].size).to.equal("md");
6767
expect(tails[1].size).to.equal("md");
6868
});
69-
70-
71-
it("removes excess tails beyond MAX_TAILS_IN_GROUP", async () => {
72-
const el = /** @type {AuroTailGroup} */ (await fixture(html`
73-
<auro-tail-group>
74-
<auro-tail tail="AS"></auro-tail>
75-
<auro-tail tail="HA"></auro-tail>
76-
<auro-tail tail="AA"></auro-tail>
77-
<auro-tail tail="OA"></auro-tail>
78-
</auro-tail-group>
79-
`));
80-
81-
// Wait for async updateChildTails
82-
await new Promise(resolve => setTimeout(resolve, 10));
83-
84-
const tails = el.querySelectorAll('auro-tail');
85-
expect(tails.length).to.equal(2); // Only first 2 should remain
86-
});
87-
88-
it("does not render shadow DOM for unsupported sizes", async () => {
89-
const el = /** @type {AuroTailGroup} */ (await fixture(html`<auro-tail-group size="xl"></auro-tail-group>`));
90-
// xl is not in GROUPS_SIZES, so no shadow DOM should be created
91-
expect(el.shadowRoot).to.be.null;
92-
});
93-
94-
it("removes all child tails for unsupported sizes", async () => {
95-
const el = /** @type {AuroTailGroup} */ (await fixture(html`
96-
<auro-tail-group size="xl">
97-
<auro-tail tail="AS"></auro-tail>
98-
<auro-tail tail="HA"></auro-tail>
99-
</auro-tail-group>
100-
`));
101-
102-
// Wait for async updateChildTails
103-
await new Promise(resolve => setTimeout(resolve, 10));
104-
105-
const tails = el.querySelectorAll('auro-tail');
106-
expect(tails.length).to.equal(0); // All should be removed
107-
});
108-
10969
it("updates child tails when size changes", async () => {
11070
const el = /** @type {AuroTailGroup} */ (await fixture(html`
11171
<auro-tail-group size="lg">

0 commit comments

Comments
 (0)