Skip to content

Commit 213eb6a

Browse files
DateBox: fix today button text customization with todayButtonText option (DevExpress#30255)
1 parent 218510e commit 213eb6a

File tree

5 files changed

+54
-12
lines changed

5 files changed

+54
-12
lines changed

packages/devextreme/js/__internal/ui/calendar/m_calendar.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export interface CalendarProperties extends Properties {
8181
viewsCount: number;
8282

8383
currentDate?: Date;
84+
85+
todayButtonText?: string;
8486
}
8587

8688
class Calendar<
@@ -146,6 +148,7 @@ class Calendar<
146148
selectionMode: 'single',
147149
selectWeekOnClick: true,
148150
showTodayButton: false,
151+
todayButtonText: messageLocalization.format('dxCalendar-todayButtonText'),
149152
showWeekNumbers: false,
150153
weekNumberRule: 'auto',
151154
cellTemplate: 'cell',
@@ -1197,15 +1200,15 @@ class Calendar<
11971200
}
11981201

11991202
_renderFooter() {
1200-
const showTodayButton = this.option('showTodayButton');
1203+
const { showTodayButton, todayButtonText: text } = this.option();
12011204

12021205
if (showTodayButton) {
12031206
const $todayButton = this._createComponent(
12041207
$('<div>'),
12051208
Button,
12061209
{
12071210
focusStateEnabled: this.option('focusStateEnabled'),
1208-
text: messageLocalization.format('dxCalendar-todayButtonText'),
1211+
text,
12091212
onClick: (args) => {
12101213
this._toTodayView(args);
12111214
},
@@ -1224,7 +1227,7 @@ class Calendar<
12241227

12251228
this.$element().append(this._$footer);
12261229
}
1227-
// @ts-expect-error ts-error
1230+
12281231
this.$element().toggleClass(CALENDAR_HAS_FOOTER_CLASS, showTodayButton);
12291232
}
12301233

@@ -1633,6 +1636,7 @@ class Calendar<
16331636
case 'dateSerializationFormat':
16341637
case 'cellTemplate':
16351638
case 'showTodayButton':
1639+
case 'todayButtonText':
16361640
this._invalidate();
16371641
break;
16381642
case 'readOnly':

packages/devextreme/js/__internal/ui/date_box/m_date_box.base.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,8 @@ class DateBox extends DropDownEditor<DateBoxBaseProperties> {
600600

601601
_isValueChanged(newValue): boolean {
602602
const oldValue = this.dateOption('value');
603-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
603+
604604
const oldTime = oldValue && oldValue.getTime();
605-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
606605
const newTime = newValue && newValue.getTime();
607606

608607
return oldTime !== newTime;
@@ -718,6 +717,7 @@ class DateBox extends DropDownEditor<DateBoxBaseProperties> {
718717
case 'interval':
719718
case 'disabledDates':
720719
case 'calendarOptions':
720+
case 'todayButtonText':
721721
this._invalidate();
722722
break;
723723
case 'displayFormat':
@@ -745,9 +745,6 @@ class DateBox extends DropDownEditor<DateBoxBaseProperties> {
745745
super._optionChanged.apply(this, arguments);
746746
this._formatValidationIcon();
747747
break;
748-
case 'todayButtonText':
749-
this._setPopupOption('toolbarItems', this._getPopupToolbarItems());
750-
break;
751748
case 'invalidDateMessage':
752749
case 'dateOutOfRangeMessage':
753750
case 'adaptivityEnabled':

packages/devextreme/js/__internal/ui/date_box/m_date_box.strategy.calendar.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CalendarStrategy extends DateBoxStrategy {
2323
getDefaultOptions() {
2424
return {
2525
...super.getDefaultOptions(),
26-
todayButtonText: messageLocalization.format('dxCalendar-todayButtonText'),
26+
todayButtonText: this.dateBox.option('todayButtonText') ?? messageLocalization.format('dxCalendar-todayButtonText'),
2727
};
2828
}
2929

@@ -99,19 +99,22 @@ class CalendarStrategy extends DateBoxStrategy {
9999
}
100100

101101
_getWidgetOptions() {
102-
const disabledDates = this.dateBox.option('disabledDates');
102+
const {
103+
disabledDates, min, max, todayButtonText,
104+
} = this.dateBox.option();
103105

104106
return extend(this.dateBox.option('calendarOptions'), {
105107
value: this.dateBoxValue() || null,
106108
selectionMode: 'single',
107109
dateSerializationFormat: null,
108-
min: this.dateBox.dateOption('min'),
109-
max: this.dateBox.dateOption('max'),
110+
min,
111+
max,
110112
onValueChanged: this._valueChangedHandler.bind(this),
111113
onCellClick: this._cellClickHandler.bind(this),
112114
disabledDates: isFunction(disabledDates) ? this._injectComponent(disabledDates.bind(this.dateBox)) : disabledDates,
113115
onContouredChanged: this._refreshActiveDescendant.bind(this),
114116
skipFocusCheck: true,
117+
todayButtonText,
115118
});
116119
}
117120

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.tests.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,30 @@ QUnit.module('Options', {
18571857
assert.strictEqual($todayButton, undefined, 'todayButton is not rendered after showTodayButton runtime change to false');
18581858
});
18591859

1860+
QUnit.test('todayButtonText option initialize', function(assert) {
1861+
const getTodayButton = () => this.$element.find(toSelector(CALENDAR_TODAY_BUTTON_CLASS)).get(0);
1862+
1863+
this.reinit({
1864+
showTodayButton: true,
1865+
todayButtonText: 'Custom text',
1866+
});
1867+
1868+
const $todayButton = getTodayButton();
1869+
assert.strictEqual($($todayButton).text(), 'Custom text', 'todayButton text matches the todayButtonText option');
1870+
});
1871+
1872+
QUnit.test('todayButtonText option', function(assert) {
1873+
const getTodayButton = () => this.$element.find(toSelector(CALENDAR_TODAY_BUTTON_CLASS)).get(0);
1874+
1875+
this.calendar.option({
1876+
showTodayButton: true,
1877+
todayButtonText: 'Custom text',
1878+
});
1879+
1880+
const $todayButton = getTodayButton();
1881+
assert.strictEqual($($todayButton).text(), 'Custom text', 'todayButton text matches the todayButtonText option');
1882+
});
1883+
18601884
QUnit.test('onCellClick option runtime change', function(assert) {
18611885
const getCellElement = () => this.$element.find(toSelector(CALENDAR_CELL_CLASS)).eq(4);
18621886

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.tests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6356,6 +6356,20 @@ QUnit.module('valueChanged handler should receive correct event', {
63566356
this.checkEvent(assert, 'dxclick', $todayButton);
63576357
this.testProgramChange(assert);
63586358
});
6359+
6360+
QUnit.test('should display custom text on today button from todayButtonText option', function(assert) {
6361+
this.instance.option({ calendarOptions: { showTodayButton: true }, todayButtonText: 'today button text' });
6362+
const $todayButton = $(this.instance.content()).parent().find(`.${CALENDAR_TODAY_BUTTON_CLASS}`);
6363+
6364+
assert.equal($todayButton.text().trim(), 'today button text');
6365+
});
6366+
6367+
QUnit.test('should display custom text on today button from todayButtonText option initialize', function(assert) {
6368+
this.reinit({ calendarOptions: { showTodayButton: true }, todayButtonText: 'today button text' });
6369+
const $todayButton = $(this.instance.content()).parent().find(`.${CALENDAR_TODAY_BUTTON_CLASS}`);
6370+
6371+
assert.equal($todayButton.text().trim(), 'today button text');
6372+
});
63596373
});
63606374

63616375
QUnit.module('validation', {

0 commit comments

Comments
 (0)