Skip to content

Commit d8832b3

Browse files
fix(atomic): don't remove field-condition, hide it instead (#6623)
Co-authored-by: developer-experience-bot[bot] <91079284+developer-experience-bot[bot]@users.noreply.github.com>
1 parent 1ec8894 commit d8832b3

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

packages/atomic/src/components/search/atomic-field-condition/atomic-field-condition.spec.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,79 +43,84 @@ describe('atomic-field-condition', () => {
4343
};
4444

4545
it('should render its content when no conditions are defined', async () => {
46-
const {content} = await renderFieldCondition();
46+
const {element, content} = await renderFieldCondition();
47+
expect(element?.hidden).toBe(false);
4748
expect(content).toBeInTheDocument();
4849
});
4950

5051
it('should render its content when an if-defined condition is met', async () => {
51-
const {content} = await renderFieldCondition({
52+
const {element, content} = await renderFieldCondition({
5253
ifDefined: 'author',
5354
resultState: {raw: {author: 'John Doe'}},
5455
});
5556

57+
expect(element?.hidden).toBe(false);
5658
expect(content).toBeInTheDocument();
5759
});
5860

5961
it('should not render its content when an if-defined condition is not met', async () => {
60-
const {content} = await renderFieldCondition({
62+
const {element} = await renderFieldCondition({
6163
ifDefined: 'author',
6264
resultState: {raw: {}},
6365
});
6466

65-
expect(content).toBeUndefined();
67+
expect(element?.hidden).toBe(true);
6668
});
6769

6870
it('should render its content when an if-not-defined condition is met', async () => {
69-
const {content} = await renderFieldCondition({
71+
const {element, content} = await renderFieldCondition({
7072
ifNotDefined: 'author',
7173
resultState: {raw: {}},
7274
});
7375

76+
expect(element?.hidden).toBe(false);
7477
expect(content).toBeInTheDocument();
7578
});
7679

7780
it('should not render its content when an if-not-defined condition is not met', async () => {
78-
const {content} = await renderFieldCondition({
81+
const {element} = await renderFieldCondition({
7982
ifNotDefined: 'author',
8083
resultState: {raw: {author: 'John Doe'}},
8184
});
8285

83-
expect(content).toBeUndefined();
86+
expect(element?.hidden).toBe(true);
8487
});
8588

8689
it('should render its content when a must-match condition is met', async () => {
87-
const {content} = await renderFieldCondition({
90+
const {element, content} = await renderFieldCondition({
8891
mustMatch: {filetype: ['pdf']},
8992
resultState: {raw: {filetype: 'pdf'}},
9093
});
9194

95+
expect(element?.hidden).toBe(false);
9296
expect(content).toBeInTheDocument();
9397
});
9498

9599
it('should not render its content when a must-match condition is not met', async () => {
96-
const {content} = await renderFieldCondition({
100+
const {element} = await renderFieldCondition({
97101
mustMatch: {filetype: ['pdf']},
98102
resultState: {raw: {filetype: 'docx'}},
99103
});
100104

101-
expect(content).toBeUndefined();
105+
expect(element?.hidden).toBe(true);
102106
});
103107

104108
it('should render its content when a must-not-match condition is met', async () => {
105-
const {content} = await renderFieldCondition({
109+
const {element, content} = await renderFieldCondition({
106110
mustNotMatch: {filetype: ['docx']},
107111
resultState: {raw: {filetype: 'pdf'}},
108112
});
109113

114+
expect(element?.hidden).toBe(false);
110115
expect(content).toBeInTheDocument();
111116
});
112117

113118
it('should not render its content when a must-not-match condition is not met', async () => {
114-
const {content} = await renderFieldCondition({
119+
const {element} = await renderFieldCondition({
115120
mustNotMatch: {filetype: ['docx']},
116121
resultState: {raw: {filetype: 'docx'}},
117122
});
118123

119-
expect(content).toBeUndefined();
124+
expect(element?.hidden).toBe(true);
120125
});
121126
});

packages/atomic/src/components/search/atomic-field-condition/atomic-field-condition.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export class AtomicFieldCondition
8585
const result = this.getResult();
8686

8787
if (!result || !this.conditions.every((condition) => condition(result))) {
88-
this.remove();
88+
// TODO: Replace this.hidden = true with this.remove() once all Search components are migrated from Stencil to Lit.
89+
// Currently using hidden to avoid breaking Stencil initialization event system in mixed Stencil/Lit component trees.
90+
this.hidden = true;
91+
return html``;
8992
}
9093

9194
return html`<slot></slot>`;

packages/atomic/src/utils/custom-element-tags.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const ATOMIC_CUSTOM_ELEMENT_TAGS = new Set<string>([
4949
'atomic-layout-section',
5050
'atomic-load-more-results',
5151
'atomic-modal',
52+
'atomic-no-results',
5253
'atomic-numeric-range',
5354
'atomic-pager',
5455
'atomic-product',

0 commit comments

Comments
 (0)