Skip to content

Commit e3996cf

Browse files
authored
fix(datetime): clear button is now rendered even if showDefaultButtons is false (#24075)
1 parent 61b99d1 commit e3996cf

File tree

2 files changed

+92
-4
lines changed

2 files changed

+92
-4
lines changed

core/src/components/datetime/datetime.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,9 @@ export class Datetime implements ComponentInterface {
980980
}
981981

982982
private renderFooter() {
983+
const { showDefaultButtons, showClearButton } = this;
983984
const hasSlottedButtons = this.el.querySelector('[slot="buttons"]') !== null;
984-
if (!hasSlottedButtons && !this.showDefaultButtons) { return; }
985+
if (!hasSlottedButtons && !showDefaultButtons && !showClearButton) { return; }
985986

986987
const clearButtonClick = () => {
987988
this.reset();
@@ -1004,10 +1005,10 @@ export class Datetime implements ComponentInterface {
10041005
}}>
10051006
<slot name="buttons">
10061007
<ion-buttons>
1007-
<ion-button color={this.color} onClick={() => this.cancel(true)}>{this.cancelText}</ion-button>
1008+
{showDefaultButtons && <ion-button id="cancel-button" color={this.color} onClick={() => this.cancel(true)}>{this.cancelText}</ion-button>}
10081009
<div>
1009-
{this.showClearButton && <ion-button color={this.color} onClick={() => clearButtonClick()}>{this.clearText}</ion-button>}
1010-
<ion-button color={this.color} onClick={() => this.confirm(true)}>{this.doneText}</ion-button>
1010+
{showClearButton && <ion-button id="clear-button" color={this.color} onClick={() => clearButtonClick()}>{this.clearText}</ion-button>}
1011+
{showDefaultButtons && <ion-button id="confirm-button" color={this.color} onClick={() => this.confirm(true)}>{this.doneText}</ion-button>}
10111012
</div>
10121013
</ion-buttons>
10131014
</slot>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { newE2EPage } from '@stencil/core/testing';
2+
import { Datetime } from '../../datetime';
3+
4+
describe('Footer', () => {
5+
test('should render default buttons', async () => {
6+
const page = await newE2EPage({
7+
components: [Datetime],
8+
html: '<ion-datetime show-default-buttons="true"></ion-datetime>'
9+
});
10+
11+
const cancelButton = await page.find('ion-datetime >>> #cancel-button');
12+
expect(cancelButton).toEqualText('Cancel');
13+
14+
const confirmButton = await page.find('ion-datetime >>> #confirm-button');
15+
expect(confirmButton).toEqualText('Done');
16+
17+
expect(await page.compareScreenshot()).toMatchScreenshot();
18+
});
19+
20+
test('should render clear button', async () => {
21+
const page = await newE2EPage({
22+
components: [Datetime],
23+
html: '<ion-datetime show-clear-button="true"></ion-datetime>'
24+
});
25+
26+
const clearButton = await page.find('ion-datetime >>> #clear-button');
27+
expect(clearButton).toEqualText('Clear');
28+
29+
expect(await page.compareScreenshot()).toMatchScreenshot();
30+
});
31+
32+
test('should render clear and default buttons', async () => {
33+
const page = await newE2EPage({
34+
components: [Datetime],
35+
html: '<ion-datetime show-default-buttons="true" show-clear-button="true"></ion-datetime>'
36+
});
37+
38+
const cancelButton = await page.find('ion-datetime >>> #cancel-button');
39+
expect(cancelButton).toEqualText('Cancel');
40+
41+
const confirmButton = await page.find('ion-datetime >>> #confirm-button');
42+
expect(confirmButton).toEqualText('Done');
43+
44+
const clearButton = await page.find('ion-datetime >>> #clear-button');
45+
expect(clearButton).toEqualText('Clear');
46+
47+
expect(await page.compareScreenshot()).toMatchScreenshot();
48+
});
49+
50+
test('should render custom buttons', async () => {
51+
const page = await newE2EPage({
52+
components: [Datetime],
53+
html: `
54+
<ion-datetime show-default-buttons="true" show-clear-button="true">
55+
<ion-buttons slot="buttons">
56+
<ion-button id="custom-button">Hello!</ion-button>
57+
</ion-buttons>
58+
</ion-datetime>
59+
`
60+
});
61+
62+
const customButton = await page.find('ion-datetime #custom-button');
63+
expect(customButton).not.toBeNull();
64+
65+
expect(await page.compareScreenshot()).toMatchScreenshot();
66+
});
67+
68+
test('should render custom buttons', async () => {
69+
const page = await newE2EPage({
70+
components: [Datetime],
71+
html: `
72+
<ion-datetime show-default-buttons="true" show-clear-button="true">
73+
<ion-buttons slot="buttons">
74+
<ion-button id="custom-button">Hello!</ion-button>
75+
</ion-buttons>
76+
</ion-datetime>
77+
`
78+
});
79+
80+
const customButton = await page.find('ion-datetime #custom-button');
81+
expect(customButton).not.toBeNull();
82+
83+
expect(await page.compareScreenshot()).toMatchScreenshot();
84+
});
85+
});
86+
87+

0 commit comments

Comments
 (0)