Skip to content

Commit 0a72f0d

Browse files
DateBox: fix today button text customization with todayButtonText option (#30259)
1 parent 1dbe4ca commit 0a72f0d

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const Calendar = Editor.inherit({
8585

8686
currentDate: new Date(),
8787

88+
todayButtonText: messageLocalization.format('dxCalendar-todayButtonText'),
89+
8890
value: null,
8991

9092
dateSerializationFormat: undefined,
@@ -1123,15 +1125,15 @@ const Calendar = Editor.inherit({
11231125
},
11241126

11251127
_renderFooter() {
1126-
const showTodayButton = this.option('showTodayButton');
1128+
const { showTodayButton, todayButtonText: text } = this.option();
11271129

11281130
if (showTodayButton) {
11291131
const $todayButton = this._createComponent(
11301132
$('<div>'),
11311133
Button,
11321134
{
11331135
focusStateEnabled: this.option('focusStateEnabled'),
1134-
text: messageLocalization.format('dxCalendar-todayButtonText'),
1136+
text,
11351137
onClick: (args) => {
11361138
this._toTodayView(args);
11371139
},
@@ -1546,6 +1548,7 @@ const Calendar = Editor.inherit({
15461548
case 'dateSerializationFormat':
15471549
case 'cellTemplate':
15481550
case 'showTodayButton':
1551+
case 'todayButtonText':
15491552
this._invalidate();
15501553
break;
15511554
case 'skipFocusCheck':

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ const DateBox = DropDownEditor.inherit({
685685
case 'interval':
686686
case 'disabledDates':
687687
case 'calendarOptions':
688+
case 'todayButtonText':
688689
this._invalidate();
689690
break;
690691
case 'displayFormat':
@@ -707,9 +708,6 @@ const DateBox = DropDownEditor.inherit({
707708
this.callBase.apply(this, arguments);
708709
this._formatValidationIcon();
709710
break;
710-
case 'todayButtonText':
711-
this._setPopupOption('toolbarItems', this._getPopupToolbarItems());
712-
break;
713711
case 'invalidDateMessage':
714712
case 'dateOutOfRangeMessage':
715713
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
@@ -17,7 +17,7 @@ const CalendarStrategy = DateBoxStrategy.inherit({
1717

1818
getDefaultOptions() {
1919
return extend(this.callBase(), {
20-
todayButtonText: messageLocalization.format('dxCalendar-todayButtonText'),
20+
todayButtonText: this.dateBox.option('todayButtonText') ?? messageLocalization.format('dxCalendar-todayButtonText'),
2121
});
2222
},
2323

@@ -90,19 +90,22 @@ const CalendarStrategy = DateBoxStrategy.inherit({
9090
},
9191

9292
_getWidgetOptions() {
93-
const disabledDates = this.dateBox.option('disabledDates');
93+
const {
94+
disabledDates, min, max, todayButtonText,
95+
} = this.dateBox.option();
9496

9597
return extend(this.dateBox.option('calendarOptions'), {
9698
value: this.dateBoxValue() || null,
9799
selectionMode: 'single',
98100
dateSerializationFormat: null,
99-
min: this.dateBox.dateOption('min'),
100-
max: this.dateBox.dateOption('max'),
101+
min,
102+
max,
101103
onValueChanged: this._valueChangedHandler.bind(this),
102104
onCellClick: this._cellClickHandler.bind(this),
103105
disabledDates: isFunction(disabledDates) ? this._injectComponent(disabledDates.bind(this.dateBox)) : disabledDates,
104106
onContouredChanged: this._refreshActiveDescendant.bind(this),
105107
skipFocusCheck: true,
108+
todayButtonText,
106109
});
107110
},
108111

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
@@ -6376,6 +6376,20 @@ QUnit.module('valueChanged handler should receive correct event', {
63766376
this.checkEvent(assert, 'dxclick', $todayButton);
63776377
this.testProgramChange(assert);
63786378
});
6379+
6380+
QUnit.test('should display custom text on today button from todayButtonText option', function(assert) {
6381+
this.instance.option({ calendarOptions: { showTodayButton: true }, todayButtonText: 'today button text' });
6382+
const $todayButton = $(this.instance.content()).parent().find(`.${CALENDAR_TODAY_BUTTON_CLASS}`);
6383+
6384+
assert.equal($todayButton.text().trim(), 'today button text');
6385+
});
6386+
6387+
QUnit.test('should display custom text on today button from todayButtonText option initialize', function(assert) {
6388+
this.reinit({ calendarOptions: { showTodayButton: true }, todayButtonText: 'today button text' });
6389+
const $todayButton = $(this.instance.content()).parent().find(`.${CALENDAR_TODAY_BUTTON_CLASS}`);
6390+
6391+
assert.equal($todayButton.text().trim(), 'today button text');
6392+
});
63796393
});
63806394

63816395
QUnit.module('validation', {

0 commit comments

Comments
 (0)