Skip to content

Commit 7e358ef

Browse files
author
Kendo Bot
committed
Sync with Kendo UI Professional
1 parent d8765dc commit 7e358ef

File tree

8 files changed

+178
-22
lines changed

8 files changed

+178
-22
lines changed

docs/api/javascript/ui/datepicker.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ The effect(s) to use when playing the open animation. Multiple effects should be
101101

102102
The duration of the open animation in milliseconds.
103103

104-
### ARIATemplate `String`*(default: "Current focused date is #=kendo.toString(data.current, 'D')#")*
104+
### ARIATemplate `String`*(default: "Current focused #=data.valueType# is #=data.text#")*
105105

106-
Specifies a template used to populate the value of the aria-label attribute of the currently focused cell of the calendar.
106+
Specifies a template used to populate the value of the aria-label attribute of the currently focused cell of the calendar. The parameters available for the template are:
107+
108+
* `current` - The current focused date.
109+
* `valueType` - The focused item value type - month, year and etc.
110+
* `text` - A text representing the focused value.
107111

108112
#### Example
109113

docs/api/javascript/ui/daterangepicker.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ Represents the Kendo UI DateRangePicker widget. Inherits from [Widget](/api/java
1111

1212
## Configuration
1313

14-
### ARIATemplate `String`*(default: "Current focused date is #=kendo.toString(data.current, 'D')#")*
14+
### ARIATemplate `String`*(default: "Current focused #=data.valueType# is #=data.text#")*
1515

16-
Specifies a template used to populate value of the aria-label attribute.
16+
Specifies a template used to populate value of the aria-label attribute of the currently focused cell of the calendar..The parameters available for the template are:
17+
18+
* `current` - The current focused date.
19+
* `valueType` - The focused item value type - month, year and etc.
20+
* `text` - A text representing the focused value.
1721

1822
#### Example
1923

docs/api/javascript/ui/datetimepicker.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ The effect(s) to use when playing the open animation. Multiple effects should be
100100

101101
The duration of the open animation in milliseconds.
102102

103-
### ARIATemplate `String`*(default: "Current focused date is #=kendo.toString(data.current, 'G')#")*
103+
### ARIATemplate `String`*(default: "Current focused #=data.valueType# is #=data.text#")*
104104

105-
Specifies a template used to populate value of the aria-label attribute.
105+
Specifies a template used to populate value of the aria-label attribute of the currently focused cell of the calendar. The parameters available for the template are:
106+
107+
* `current` - The current focused date.
108+
* `valueType` - The focused item value type - month, year and etc.
109+
* `text` - A text representing the focused value.
106110

107111
#### Example
108112

src/kendo.calendar.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,26 @@ var __meta__ = { // jshint ignore:line
13401340
}
13411341

13421342
that.footer = footer !== false ? template(footerTemplate, { useWithBlock: false }) : null;
1343+
},
1344+
1345+
_updateAria: function (ariaTemplate, date) {
1346+
var that = this;
1347+
var cell = that._cell;
1348+
var valueType = that.view().valueType();
1349+
var current = date || that.current();
1350+
var text;
1351+
1352+
if (valueType === "month") {
1353+
text = kendo.toString(current, "MMMM");
1354+
} else if (valueType === "date") {
1355+
text = kendo.toString(current, "D");
1356+
} else {
1357+
text = cell.text();
1358+
}
1359+
1360+
cell.attr("aria-label", ariaTemplate({ current: current, valueType: valueType, text: text }));
1361+
1362+
return cell.attr("id");
13431363
}
13441364
});
13451365

@@ -1526,6 +1546,9 @@ var __meta__ = { // jshint ignore:line
15261546
},
15271547
toDateString: function(date) {
15281548
return date.getFullYear() + "/" + date.getMonth() + "/" + date.getDate();
1549+
},
1550+
valueType: function () {
1551+
return "date";
15291552
}
15301553
},
15311554
{
@@ -1601,6 +1624,9 @@ var __meta__ = { // jshint ignore:line
16011624
},
16021625
toDateString: function(date) {
16031626
return date.getFullYear() + "/" + date.getMonth() + "/1";
1627+
},
1628+
valueType: function () {
1629+
return "month";
16041630
}
16051631
},
16061632
{
@@ -1652,6 +1678,9 @@ var __meta__ = { // jshint ignore:line
16521678
},
16531679
toDateString: function(date) {
16541680
return date.getFullYear() + "/0/1";
1681+
},
1682+
valueType: function () {
1683+
return "year";
16551684
}
16561685
},
16571686
{
@@ -1726,6 +1755,9 @@ var __meta__ = { // jshint ignore:line
17261755
toDateString: function(date) {
17271756
var year = date.getFullYear();
17281757
return (year - year % 10) + "/0/1";
1758+
},
1759+
valueType: function () {
1760+
return "decade";
17291761
}
17301762
}]
17311763
};

src/kendo.datepicker.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ var __meta__ = { // jshint ignore:line
403403
month: {},
404404
dates: [],
405405
disableDates: null,
406-
ARIATemplate: 'Current focused date is #=kendo.toString(data.current, "D")#',
406+
ARIATemplate: 'Current focused #=data.valueType# is #=data.text#',
407407
dateInput: false,
408408
weekNumber: false,
409409
componentType: "classic"
@@ -761,7 +761,7 @@ var __meta__ = { // jshint ignore:line
761761
},
762762

763763
_template: function() {
764-
this._ariaTemplate = template(this.options.ARIATemplate);
764+
this._ariaTemplate = proxy(template(this.options.ARIATemplate), this);
765765
},
766766

767767
_createDateInput: function(options) {
@@ -781,17 +781,15 @@ var __meta__ = { // jshint ignore:line
781781
},
782782

783783
_updateARIA: function(date) {
784-
var cell;
785784
var that = this;
786785
var calendar = that.dateView.calendar;
787-
if(that.element && that.element.length) {
786+
787+
if (that.element && that.element.length) {
788788
that.element[0].removeAttribute("aria-activedescendant");
789789
}
790-
if (calendar) {
791-
cell = calendar._cell;
792-
cell.attr("aria-label", that._ariaTemplate({ current: date || calendar.current() }));
793790

794-
that.element.attr("aria-activedescendant", cell.attr("id"));
791+
if (calendar) {
792+
that.element.attr("aria-activedescendant", calendar._updateAria(that._ariaTemplate, date));
795793
}
796794
}
797795
});

src/kendo.datetimepicker.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ var __meta__ = { // jshint ignore:line
158158
depth: MONTH,
159159
animation: {},
160160
month : {},
161-
ARIATemplate: 'Current focused date is #=kendo.toString(data.current, "d")#',
161+
ARIATemplate: 'Current focused #=data.valueType# is #=data.text#',
162162
dateButtonText: "Open the date view",
163163
timeButtonText: "Open the time view",
164164
dateInput: false,
@@ -946,7 +946,7 @@ var __meta__ = { // jshint ignore:line
946946
},
947947

948948
_template: function() {
949-
this._ariaTemplate = kendo.template(this.options.ARIATemplate);
949+
this._ariaTemplate = $.proxy(kendo.template(this.options.ARIATemplate), this);
950950
},
951951

952952
_createDateInput: function(options) {
@@ -971,19 +971,15 @@ var __meta__ = { // jshint ignore:line
971971
},
972972

973973
_updateARIA: function(date) {
974-
var cell;
975974
var that = this;
976975
var calendar = that.dateView.calendar;
977976

978-
if(that.element && that.element.length) {
977+
if (that.element && that.element.length) {
979978
that.element[0].removeAttribute(ARIA_ACTIVEDESCENDANT);
980979
}
981980

982981
if (calendar) {
983-
cell = calendar._cell;
984-
cell.attr("aria-label", that._ariaTemplate({ current: date || calendar.current() }));
985-
986-
that.element.attr(ARIA_ACTIVEDESCENDANT, cell.attr("id"));
982+
that.element.attr(ARIA_ACTIVEDESCENDANT, calendar._updateAria(that._ariaTemplate, date));
987983
}
988984
},
989985
_popup: function(){

tests/datepicker/aria.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,65 @@ it("DatePicker removes aria-label from previous cell", function() {
110110
assert.equal(cell.length, 1);
111111
});
112112

113+
});
114+
115+
describe("kendo.ui.DatePicker ARIA defaults", function () {
116+
beforeEach(function() {
117+
118+
input = $("<input id='test' />").appendTo(Mocha.fixture);
119+
});
120+
afterEach(function() {
121+
122+
instance.destroy();
123+
kendo.destroy(Mocha.fixture);
113124
});
125+
126+
it("DatePicker add correct aria-label for date", function() {
127+
instance = new DatePicker(input);
128+
instance.open();
129+
130+
var date = kendo.date.today();
131+
instance.element.trigger("focus");
132+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
133+
134+
assert.equal(cell.attr("aria-label"), "Current focused date is "+kendo.toString(date, "D"));
135+
});
136+
137+
it("DatePicker add correct aria-label for year", function() {
138+
var date = kendo.date.today();
139+
instance = new DatePicker(input, { start: "year"});
140+
instance.open();
141+
instance.element.trigger("focus");
142+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
143+
assert.equal(cell.attr("aria-label"), "Current focused month is "+kendo.toString(date, "MMMM"));
144+
});
145+
146+
it("DatePicker add evaluates ariatemplate in correct context", function() {
147+
var date = kendo.date.today();
148+
instance = new DatePicker(input, { ARIATemplate: "Current focused date is #= this.dateView.calendar.view().name === 'month' ? 'test': kendo.toString(data.current, 'MMM yyyy') #"});
149+
instance.open();
150+
instance.element.trigger("focus");
151+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
152+
assert.equal(cell.attr("aria-label"), "Current focused date is test");
153+
});
154+
155+
it("DatePicker add correct aria-label for decade", function() {
156+
var date = kendo.date.today();
157+
instance = new DatePicker(input, { start: "decade"});
158+
instance.open();
159+
instance.element.trigger("focus");
160+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
161+
assert.equal(cell.attr("aria-label"), "Current focused year is "+kendo.toString(date, "yyyy"));
162+
});
163+
164+
it("DatePicker add correct aria-label for century", function() {
165+
instance = new DatePicker(input, { start: "century", value: new Date(2021, 0, 1)});
166+
instance.open();
167+
instance.element.trigger("focus");
168+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
169+
170+
assert.equal(cell.attr("aria-label"), "Current focused decade is 2020 - 2029");
171+
});
172+
173+
});
114174
}());

tests/datetimepicker/aria.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,62 @@
123123
});
124124

125125
});
126+
127+
describe("kendo.ui.DateTimePicker ARIA defaults", function () {
128+
beforeEach(function() {
129+
130+
input = $("<input id='test' />").appendTo(Mocha.fixture);
131+
});
132+
afterEach(function() {
133+
134+
instance.destroy();
135+
kendo.destroy(Mocha.fixture);
136+
});
137+
138+
it("DateTimePicker add correct aria-label for date", function() {
139+
instance = new DateTimePicker(input);
140+
instance.open();
141+
142+
var date = kendo.date.today();
143+
instance.element.trigger("focus");
144+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
145+
146+
assert.equal(cell.attr("aria-label"), "Current focused date is "+kendo.toString(date, "D"));
147+
});
148+
149+
it("DateTimePicker add evaluates ariatemplate in correct context", function() {
150+
instance = new DateTimePicker(input, { ARIATemplate: "Current focused date is #= this.dateView.calendar.view().name === 'month' ? 'test': kendo.toString(data.current, 'MMM yyyy') #"});
151+
instance.open();
152+
instance.element.trigger("focus");
153+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
154+
assert.equal(cell.attr("aria-label"), "Current focused date is test");
155+
});
156+
157+
it("DateTimePicker add correct aria-label for year", function() {
158+
var date = kendo.date.today();
159+
instance = new DateTimePicker(input, { start: "year"});
160+
instance.open();
161+
instance.element.trigger("focus");
162+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
163+
assert.equal(cell.attr("aria-label"), "Current focused month is "+kendo.toString(date, "MMMM"));
164+
});
165+
166+
it("DateTimePicker add correct aria-label for decade", function() {
167+
var date = kendo.date.today();
168+
instance = new DateTimePicker(input, { start: "decade"});
169+
instance.open();
170+
instance.element.trigger("focus");
171+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
172+
assert.equal(cell.attr("aria-label"), "Current focused year is "+kendo.toString(date, "yyyy"));
173+
});
174+
175+
it("DateTimePicker add correct aria-label for century", function() {
176+
instance = new DateTimePicker(input, { start: "century", value: new Date(2021, 0, 1)});
177+
instance.open();
178+
instance.element.trigger("focus");
179+
var cell = instance.dateView.calendar.element.find("td.k-state-focused");
180+
181+
assert.equal(cell.attr("aria-label"), "Current focused decade is 2020 - 2029");
182+
});
183+
});
126184
}());

0 commit comments

Comments
 (0)