@ohos-ports/flowbite-datepicker 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +73 -0
  3. package/.stylelintrc +12 -0
  4. package/CHANGELOG.md +72 -0
  5. package/LICENSE +21 -0
  6. package/README.md +71 -0
  7. package/demo/index.html +582 -0
  8. package/demo/live-demo.js +471 -0
  9. package/dist/DateRangePicker.cjs.js +2996 -0
  10. package/dist/DateRangePicker.esm.js +2994 -0
  11. package/dist/DateRangePicker.umd.js +3002 -0
  12. package/dist/Datepicker.cjs.js +2778 -0
  13. package/dist/Datepicker.esm.js +2776 -0
  14. package/dist/Datepicker.umd.js +2784 -0
  15. package/dist/css/datepicker-bs4.css +276 -0
  16. package/dist/css/datepicker-bs4.min.css +1 -0
  17. package/dist/css/datepicker-bs5.css +276 -0
  18. package/dist/css/datepicker-bs5.min.css +1 -0
  19. package/dist/css/datepicker-bulma.css +258 -0
  20. package/dist/css/datepicker-bulma.min.css +1 -0
  21. package/dist/css/datepicker-foundation.css +262 -0
  22. package/dist/css/datepicker-foundation.min.css +1 -0
  23. package/dist/css/datepicker.css +306 -0
  24. package/dist/css/datepicker.min.css +1403 -0
  25. package/dist/js/datepicker-full.js +2777 -0
  26. package/dist/js/datepicker-full.min.js +1 -0
  27. package/dist/js/datepicker.js +2569 -0
  28. package/dist/js/datepicker.min.js +1 -0
  29. package/dist/js/locales/ar-tn.js +15 -0
  30. package/dist/js/locales/ar.js +15 -0
  31. package/dist/js/locales/az.js +14 -0
  32. package/dist/js/locales/bg.js +14 -0
  33. package/dist/js/locales/bm.js +18 -0
  34. package/dist/js/locales/bn.js +19 -0
  35. package/dist/js/locales/br.js +18 -0
  36. package/dist/js/locales/bs.js +15 -0
  37. package/dist/js/locales/ca.js +18 -0
  38. package/dist/js/locales/cs.js +19 -0
  39. package/dist/js/locales/cy.js +14 -0
  40. package/dist/js/locales/da.js +19 -0
  41. package/dist/js/locales/de.js +18 -0
  42. package/dist/js/locales/el.js +16 -0
  43. package/dist/js/locales/en-AU.js +18 -0
  44. package/dist/js/locales/en-CA.js +18 -0
  45. package/dist/js/locales/en-GB.js +18 -0
  46. package/dist/js/locales/en-IE.js +17 -0
  47. package/dist/js/locales/en-NZ.js +17 -0
  48. package/dist/js/locales/en-ZA.js +17 -0
  49. package/dist/js/locales/eo.js +17 -0
  50. package/dist/js/locales/es.js +18 -0
  51. package/dist/js/locales/et.js +18 -0
  52. package/dist/js/locales/eu.js +18 -0
  53. package/dist/js/locales/fa.js +17 -0
  54. package/dist/js/locales/fi.js +17 -0
  55. package/dist/js/locales/fo.js +15 -0
  56. package/dist/js/locales/fr-CH.js +21 -0
  57. package/dist/js/locales/fr.js +18 -0
  58. package/dist/js/locales/gl.js +16 -0
  59. package/dist/js/locales/he.js +15 -0
  60. package/dist/js/locales/hi.js +18 -0
  61. package/dist/js/locales/hr.js +13 -0
  62. package/dist/js/locales/hu.js +18 -0
  63. package/dist/js/locales/hy.js +18 -0
  64. package/dist/js/locales/id.js +15 -0
  65. package/dist/js/locales/is.js +14 -0
  66. package/dist/js/locales/it-CH.js +20 -0
  67. package/dist/js/locales/it.js +18 -0
  68. package/dist/js/locales/ja.js +17 -0
  69. package/dist/js/locales/ka.js +17 -0
  70. package/dist/js/locales/kk.js +15 -0
  71. package/dist/js/locales/km.js +15 -0
  72. package/dist/js/locales/ko.js +18 -0
  73. package/dist/js/locales/lt.js +19 -0
  74. package/dist/js/locales/lv.js +18 -0
  75. package/dist/js/locales/me.js +17 -0
  76. package/dist/js/locales/mk.js +15 -0
  77. package/dist/js/locales/mn.js +17 -0
  78. package/dist/js/locales/mr.js +18 -0
  79. package/dist/js/locales/ms.js +15 -0
  80. package/dist/js/locales/nl-BE.js +18 -0
  81. package/dist/js/locales/nl.js +18 -0
  82. package/dist/js/locales/no.js +18 -0
  83. package/dist/js/locales/oc.js +17 -0
  84. package/dist/js/locales/pl.js +17 -0
  85. package/dist/js/locales/pt-BR.js +17 -0
  86. package/dist/js/locales/pt.js +18 -0
  87. package/dist/js/locales/ro.js +17 -0
  88. package/dist/js/locales/ru.js +18 -0
  89. package/dist/js/locales/si.js +18 -0
  90. package/dist/js/locales/sk.js +18 -0
  91. package/dist/js/locales/sl.js +15 -0
  92. package/dist/js/locales/sq.js +18 -0
  93. package/dist/js/locales/sr-latn.js +16 -0
  94. package/dist/js/locales/sr.js +16 -0
  95. package/dist/js/locales/sv.js +17 -0
  96. package/dist/js/locales/sw.js +15 -0
  97. package/dist/js/locales/ta.js +18 -0
  98. package/dist/js/locales/tg.js +19 -0
  99. package/dist/js/locales/th.js +14 -0
  100. package/dist/js/locales/tk.js +18 -0
  101. package/dist/js/locales/tr.js +17 -0
  102. package/dist/js/locales/uk.js +17 -0
  103. package/dist/js/locales/uz-cyrl.js +18 -0
  104. package/dist/js/locales/uz-latn.js +18 -0
  105. package/dist/js/locales/vi.js +16 -0
  106. package/dist/js/locales/zh-CN.js +19 -0
  107. package/dist/js/locales/zh-TW.js +18 -0
  108. package/dist/locales/index.cjs.js +1028 -0
  109. package/dist/locales/index.esm.js +1028 -0
  110. package/dist/main.cjs.js +2999 -0
  111. package/dist/main.esm.js +2994 -0
  112. package/dist/main.umd.js +3005 -0
  113. package/docs/.nojekyll +0 -0
  114. package/docs/README.md +266 -0
  115. package/docs/_sidebar.md +6 -0
  116. package/docs/api.md +284 -0
  117. package/docs/date-string+format.md +90 -0
  118. package/docs/i18n.md +99 -0
  119. package/docs/images/datepicker-inline.jpg +0 -0
  120. package/docs/images/datepicker.jpg +0 -0
  121. package/docs/images/multidate.jpg +0 -0
  122. package/docs/images/picker-structure.jpg +0 -0
  123. package/docs/images/rangepicker.jpg +0 -0
  124. package/docs/images/view-days.jpg +0 -0
  125. package/docs/images/view-decades.jpg +0 -0
  126. package/docs/images/view-months.jpg +0 -0
  127. package/docs/images/view-years.jpg +0 -0
  128. package/docs/index.html +26 -0
  129. package/docs/options.md +354 -0
  130. package/docs/overview.md +174 -0
  131. package/extras/twoDigitToFullYear/test/twoDigitToFullYear.js +58 -0
  132. package/extras/twoDigitToFullYear/twoDigitToFullYear.js +26 -0
  133. package/js/DateRangePicker.js +210 -0
  134. package/js/Datepicker.js +487 -0
  135. package/js/datepicker-full.js +5 -0
  136. package/js/events/functions.js +48 -0
  137. package/js/events/inputFieldListeners.js +206 -0
  138. package/js/events/otherListeners.js +15 -0
  139. package/js/events/pickerListeners.js +70 -0
  140. package/js/i18n/base-locales.js +13 -0
  141. package/js/i18n/locales/ar-tn.js +15 -0
  142. package/js/i18n/locales/ar.js +15 -0
  143. package/js/i18n/locales/az.js +14 -0
  144. package/js/i18n/locales/bg.js +14 -0
  145. package/js/i18n/locales/bm.js +18 -0
  146. package/js/i18n/locales/bn.js +19 -0
  147. package/js/i18n/locales/br.js +18 -0
  148. package/js/i18n/locales/bs.js +15 -0
  149. package/js/i18n/locales/ca.js +18 -0
  150. package/js/i18n/locales/cs.js +19 -0
  151. package/js/i18n/locales/cy.js +14 -0
  152. package/js/i18n/locales/da.js +19 -0
  153. package/js/i18n/locales/de.js +18 -0
  154. package/js/i18n/locales/el.js +16 -0
  155. package/js/i18n/locales/en-AU.js +18 -0
  156. package/js/i18n/locales/en-CA.js +18 -0
  157. package/js/i18n/locales/en-GB.js +18 -0
  158. package/js/i18n/locales/en-IE.js +17 -0
  159. package/js/i18n/locales/en-NZ.js +17 -0
  160. package/js/i18n/locales/en-ZA.js +17 -0
  161. package/js/i18n/locales/eo.js +17 -0
  162. package/js/i18n/locales/es.js +18 -0
  163. package/js/i18n/locales/et.js +18 -0
  164. package/js/i18n/locales/eu.js +18 -0
  165. package/js/i18n/locales/fa.js +17 -0
  166. package/js/i18n/locales/fi.js +17 -0
  167. package/js/i18n/locales/fo.js +15 -0
  168. package/js/i18n/locales/fr-CH.js +21 -0
  169. package/js/i18n/locales/fr.js +18 -0
  170. package/js/i18n/locales/gl.js +16 -0
  171. package/js/i18n/locales/he.js +15 -0
  172. package/js/i18n/locales/hi.js +18 -0
  173. package/js/i18n/locales/hr.js +13 -0
  174. package/js/i18n/locales/hu.js +18 -0
  175. package/js/i18n/locales/hy.js +18 -0
  176. package/js/i18n/locales/id.js +15 -0
  177. package/js/i18n/locales/is.js +14 -0
  178. package/js/i18n/locales/it-CH.js +20 -0
  179. package/js/i18n/locales/it.js +18 -0
  180. package/js/i18n/locales/ja.js +17 -0
  181. package/js/i18n/locales/ka.js +17 -0
  182. package/js/i18n/locales/kk.js +15 -0
  183. package/js/i18n/locales/km.js +15 -0
  184. package/js/i18n/locales/ko.js +18 -0
  185. package/js/i18n/locales/lt.js +19 -0
  186. package/js/i18n/locales/lv.js +18 -0
  187. package/js/i18n/locales/me.js +17 -0
  188. package/js/i18n/locales/mk.js +15 -0
  189. package/js/i18n/locales/mn.js +17 -0
  190. package/js/i18n/locales/mr.js +18 -0
  191. package/js/i18n/locales/ms.js +15 -0
  192. package/js/i18n/locales/nl-BE.js +18 -0
  193. package/js/i18n/locales/nl.js +18 -0
  194. package/js/i18n/locales/no.js +18 -0
  195. package/js/i18n/locales/oc.js +17 -0
  196. package/js/i18n/locales/pl.js +17 -0
  197. package/js/i18n/locales/pt-BR.js +17 -0
  198. package/js/i18n/locales/pt.js +18 -0
  199. package/js/i18n/locales/ro.js +17 -0
  200. package/js/i18n/locales/ru.js +18 -0
  201. package/js/i18n/locales/si.js +18 -0
  202. package/js/i18n/locales/sk.js +18 -0
  203. package/js/i18n/locales/sl.js +15 -0
  204. package/js/i18n/locales/sq.js +18 -0
  205. package/js/i18n/locales/sr-latn.js +16 -0
  206. package/js/i18n/locales/sr.js +16 -0
  207. package/js/i18n/locales/sv.js +17 -0
  208. package/js/i18n/locales/sw.js +15 -0
  209. package/js/i18n/locales/ta.js +18 -0
  210. package/js/i18n/locales/tg.js +19 -0
  211. package/js/i18n/locales/th.js +14 -0
  212. package/js/i18n/locales/tk.js +18 -0
  213. package/js/i18n/locales/tr.js +17 -0
  214. package/js/i18n/locales/uk.js +17 -0
  215. package/js/i18n/locales/uz-cyrl.js +18 -0
  216. package/js/i18n/locales/uz-latn.js +18 -0
  217. package/js/i18n/locales/vi.js +16 -0
  218. package/js/i18n/locales/zh-CN.js +19 -0
  219. package/js/i18n/locales/zh-TW.js +18 -0
  220. package/js/lib/date-format.js +185 -0
  221. package/js/lib/date.js +82 -0
  222. package/js/lib/dom.js +55 -0
  223. package/js/lib/event.js +68 -0
  224. package/js/lib/utils.js +61 -0
  225. package/js/main.js +4 -0
  226. package/js/options/defaultOptions.js +38 -0
  227. package/js/options/processOptions.js +263 -0
  228. package/js/picker/Picker.js +334 -0
  229. package/js/picker/templates/calendarWeeksTemplate.js +8 -0
  230. package/js/picker/templates/daysTemplate.js +8 -0
  231. package/js/picker/templates/pickerTemplate.js +23 -0
  232. package/js/picker/views/DaysView.js +250 -0
  233. package/js/picker/views/MonthsView.js +198 -0
  234. package/js/picker/views/View.js +55 -0
  235. package/js/picker/views/YearsView.js +170 -0
  236. package/package.json +81 -0
  237. package/postcss.config.js +5 -0
  238. package/rollup.config.js +75 -0
  239. package/sass/_mixins.scss +12 -0
  240. package/sass/datepicker-bs4.scss +91 -0
  241. package/sass/datepicker-bs5.scss +91 -0
  242. package/sass/datepicker-bulma.scss +69 -0
  243. package/sass/datepicker-foundation.scss +66 -0
  244. package/sass/datepicker.scss +436 -0
  245. package/sass/index-bs4.scss +5 -0
  246. package/sass/index-bs5.scss +5 -0
  247. package/sass/index-bulma.scss +6 -0
  248. package/sass/index-foundation.scss +3 -0
  249. package/scripts/build-css.js +39 -0
  250. package/scripts/build-locales.js +57 -0
  251. package/scripts/convert-bsdp-locales.js +65 -0
  252. package/scripts/minify-css.js +31 -0
  253. package/scripts/minify-js.js +17 -0
  254. package/style.css +10 -0
  255. package/tailwind.config.js +16 -0
  256. package/tailwind.css +1389 -0
  257. package/test/DateRangePicker/DateRangePicker.js +547 -0
  258. package/test/DateRangePicker/api-methods.js +415 -0
  259. package/test/DateRangePicker/date-selection.js +472 -0
  260. package/test/DateRangePicker/options.js +308 -0
  261. package/test/Datepicker/Datepicker-object.js +236 -0
  262. package/test/Datepicker/api-methods.js +328 -0
  263. package/test/_utils/date.js +102 -0
  264. package/test/_utils/dom.js +70 -0
  265. package/test/events.js +785 -0
  266. package/test/inline-mode.js +45 -0
  267. package/test/keyboard-operation/arrow-down.js +293 -0
  268. package/test/keyboard-operation/arrow-left.js +255 -0
  269. package/test/keyboard-operation/arrow-right.js +215 -0
  270. package/test/keyboard-operation/arrow-up.js +461 -0
  271. package/test/keyboard-operation/edit-mode.js +458 -0
  272. package/test/keyboard-operation/keyboard-operation.js +146 -0
  273. package/test/mouse-operation.js +580 -0
  274. package/test/options/before-show.js +635 -0
  275. package/test/options/bulma-datepicker.sublime-workspace +1280 -0
  276. package/test/options/buttons.js +383 -0
  277. package/test/options/date-restrictions.js +802 -0
  278. package/test/options/format.js +281 -0
  279. package/test/options/multidate.js +380 -0
  280. package/test/options/options.js +727 -0
  281. package/test/options/orientation.js +410 -0
  282. package/test/options/pick-levle+view.js +357 -0
  283. package/test/test.html +94 -0
  284. package/test/unit/DateRangePicker.js +192 -0
  285. package/test/unit/Datepicker.js +307 -0
  286. package/test/unit/_setup.js +28 -0
  287. package/test/unit/lib/date-format.js +310 -0
  288. package/test/unit/lib/date.js +211 -0
  289. package/test/unit/lib/dom.js +142 -0
  290. package/test/unit/lib/event.js +207 -0
  291. package/test/unit/lib/utils.js +135 -0
@@ -0,0 +1,458 @@
1
+ describe('keyboard operation - edit mode', function () {
2
+ let input;
3
+
4
+ beforeEach(function () {
5
+ input = document.createElement('input');
6
+ testContainer.appendChild(input);
7
+ });
8
+
9
+ afterEach(function () {
10
+ testContainer.removeChild(input);
11
+ });
12
+
13
+ it('turns on when Datepicker.enterEditMode() is called', function () {
14
+ const dp = new Datepicker(input);
15
+ input.focus();
16
+ dp.enterEditMode();
17
+
18
+ expect(dp.editMode, 'to be true');
19
+ expect(input.classList.contains('in-edit'), 'to be true');
20
+
21
+ dp.destroy();
22
+ input.classList.remove('in-edit');
23
+ });
24
+
25
+ it('turns on when a printable letter, backspace or delete key is pressed without ctrl/meta', function () {
26
+ const dp = new Datepicker(input);
27
+ input.focus();
28
+
29
+ simulant.fire(input, 'keydown', {key: '1'});
30
+ expect(dp.editMode, 'to be true');
31
+
32
+ delete dp.editMode;
33
+ input.classList.remove('in-edit');
34
+
35
+ simulant.fire(input, 'keydown', {key: 'J'});
36
+ expect(dp.editMode, 'to be true');
37
+
38
+ delete dp.editMode;
39
+ input.classList.remove('in-edit');
40
+
41
+ simulant.fire(input, 'keydown', {key: '/'});
42
+ expect(dp.editMode, 'to be true');
43
+
44
+ delete dp.editMode;
45
+ input.classList.remove('in-edit');
46
+
47
+ simulant.fire(input, 'keydown', {key: ' '});
48
+ expect(dp.editMode, 'to be true');
49
+
50
+ delete dp.editMode;
51
+ input.classList.remove('in-edit');
52
+
53
+ simulant.fire(input, 'keydown', {key: 'Backspace'});
54
+ expect(dp.editMode, 'to be true');
55
+
56
+ delete dp.editMode;
57
+ input.classList.remove('in-edit');
58
+
59
+ simulant.fire(input, 'keydown', {key: 'Delete'});
60
+ expect(dp.editMode, 'to be true');
61
+
62
+ delete dp.editMode;
63
+ input.classList.remove('in-edit');
64
+
65
+ // with modifier key
66
+ simulant.fire(input, 'keydown', {key: '1', shiftKey: true});
67
+ expect(dp.editMode, 'to be true');
68
+
69
+ delete dp.editMode;
70
+ input.classList.remove('in-edit');
71
+
72
+ simulant.fire(input, 'keydown', {key: '1', altKey: true});
73
+ expect(dp.editMode, 'to be true');
74
+
75
+ delete dp.editMode;
76
+ input.classList.remove('in-edit');
77
+
78
+ simulant.fire(input, 'keydown', {key: '1', ctrlKey: true});
79
+ expect(dp.editMode, 'to be undefined');
80
+ expect(input.classList.contains('in-edit'), 'to be false');
81
+
82
+ simulant.fire(input, 'keydown', {key: '1', metaKey: true});
83
+ expect(dp.editMode, 'to be undefined');
84
+ expect(input.classList.contains('in-edit'), 'to be false');
85
+
86
+ // non-pritable-letter key
87
+ simulant.fire(input, 'keydown', {key: 'PageDown'});
88
+ expect(dp.editMode, 'to be undefined');
89
+ expect(input.classList.contains('in-edit'), 'to be false');
90
+
91
+ simulant.fire(input, 'keydown', {key: 'Escape', ctrlKey: true});
92
+ expect(dp.editMode, 'to be undefined');
93
+
94
+ dp.destroy();
95
+ });
96
+
97
+ it('turns on when shift + either of arrow keys is pressed without ctrl/meta', function () {
98
+ const dp = new Datepicker(input);
99
+ input.focus();
100
+
101
+ // shift + arrow
102
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', shiftKey: true});
103
+ expect(dp.editMode, 'to be true');
104
+
105
+ delete dp.editMode;
106
+ input.classList.remove('in-edit');
107
+
108
+ simulant.fire(input, 'keydown', {key: 'ArrowRight', shiftKey: true});
109
+ expect(dp.editMode, 'to be true');
110
+
111
+ delete dp.editMode;
112
+ input.classList.remove('in-edit');
113
+
114
+ simulant.fire(input, 'keydown', {key: 'ArrowUp', shiftKey: true});
115
+ expect(dp.editMode, 'to be true');
116
+
117
+ delete dp.editMode;
118
+ input.classList.remove('in-edit');
119
+
120
+ simulant.fire(input, 'keydown', {key: 'ArrowDown', shiftKey: true});
121
+ expect(dp.editMode, 'to be true');
122
+
123
+ delete dp.editMode;
124
+ input.classList.remove('in-edit');
125
+
126
+ // arrow + other modifire key
127
+ // arrow-left
128
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', altKey: true});
129
+ expect(dp.editMode, 'to be undefined');
130
+
131
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', ctrlKey: true});
132
+ expect(dp.editMode, 'to be undefined');
133
+
134
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', metaKey: true});
135
+ expect(dp.editMode, 'to be undefined');
136
+
137
+ // arrow-right
138
+ simulant.fire(input, 'keydown', {key: 'ArrowRight', altKey: true});
139
+ expect(dp.editMode, 'to be undefined');
140
+
141
+ simulant.fire(input, 'keydown', {key: 'ArrowRight', ctrlKey: true});
142
+ expect(dp.editMode, 'to be undefined');
143
+
144
+ simulant.fire(input, 'keydown', {key: 'ArrowRight', metaKey: true});
145
+ expect(dp.editMode, 'to be undefined');
146
+
147
+ // arrow-up
148
+ simulant.fire(input, 'keydown', {key: 'ArrowUp', altKey: true});
149
+ expect(dp.editMode, 'to be undefined');
150
+
151
+ simulant.fire(input, 'keydown', {key: 'ArrowUp', ctrlKey: true});
152
+ expect(dp.editMode, 'to be undefined');
153
+
154
+ simulant.fire(input, 'keydown', {key: 'ArrowUp', metaKey: true});
155
+ expect(dp.editMode, 'to be undefined');
156
+
157
+ // arrow-down
158
+ simulant.fire(input, 'keydown', {key: 'ArrowDown', altKey: true});
159
+ expect(dp.editMode, 'to be undefined');
160
+
161
+ simulant.fire(input, 'keydown', {key: 'ArrowDown', ctrlKey: true});
162
+ expect(dp.editMode, 'to be undefined');
163
+
164
+ simulant.fire(input, 'keydown', {key: 'ArrowDown', metaKey: true});
165
+ expect(dp.editMode, 'to be undefined');
166
+
167
+ // shift + arrow with other modifier key
168
+ // arrow-left
169
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', shiftKey: true, altKey: true});
170
+ expect(dp.editMode, 'to be true');
171
+
172
+ delete dp.editMode;
173
+ input.classList.remove('in-edit');
174
+
175
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', shiftKey: true, ctrlKey: true});
176
+ expect(dp.editMode, 'to be undefined');
177
+
178
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft', shiftKey: true, metaKey: true});
179
+ expect(dp.editMode, 'to be undefined');
180
+
181
+ // arrow-right
182
+ simulant.fire(input, 'keydown', {key: 'ArrowRight', shiftKey: true, altKey: true});
183
+ expect(dp.editMode, 'to be true');
184
+
185
+ delete dp.editMode;
186
+ input.classList.remove('in-edit');
187
+
188
+ simulant.fire(input, 'keydown', {key: 'ArrowRight', shiftKey: true, ctrlKey: true});
189
+ expect(dp.editMode, 'to be undefined');
190
+
191
+ simulant.fire(input, 'keydown', {key: 'ArrowRight', shiftKey: true, metaKey: true});
192
+ expect(dp.editMode, 'to be undefined');
193
+
194
+ // arrow-up
195
+ simulant.fire(input, 'keydown', {key: 'ArrowUp', shiftKey: true, altKey: true});
196
+ expect(dp.editMode, 'to be true');
197
+
198
+ delete dp.editMode;
199
+ input.classList.remove('in-edit');
200
+
201
+ simulant.fire(input, 'keydown', {key: 'ArrowUp', shiftKey: true, ctrlKey: true});
202
+ expect(dp.editMode, 'to be undefined');
203
+
204
+ simulant.fire(input, 'keydown', {key: 'ArrowUp', shiftKey: true, metaKey: true});
205
+ expect(dp.editMode, 'to be undefined');
206
+
207
+ // arrow-down
208
+ simulant.fire(input, 'keydown', {key: 'ArrowDown', shiftKey: true, altKey: true});
209
+ expect(dp.editMode, 'to be true');
210
+
211
+ delete dp.editMode;
212
+ input.classList.remove('in-edit');
213
+
214
+ simulant.fire(input, 'keydown', {key: 'ArrowDown', shiftKey: true, ctrlKey: true});
215
+ expect(dp.editMode, 'to be undefined');
216
+
217
+ simulant.fire(input, 'keydown', {key: 'ArrowDown', shiftKey: true, metaKey: true});
218
+ expect(dp.editMode, 'to be undefined');
219
+
220
+ dp.destroy();
221
+ });
222
+
223
+ it('turns on when input is clicked', function () {
224
+ const dp = new Datepicker(input);
225
+ input.focus();
226
+
227
+ simulant.fire(input, 'mousedown');
228
+ input.click();
229
+ expect(dp.editMode, 'to be true');
230
+ expect(input.classList.contains('in-edit'), 'to be true');
231
+
232
+ dp.destroy();
233
+ input.classList.remove('in-edit');
234
+ });
235
+
236
+ it('does not turn on when the picker is hidden', function () {
237
+ const dp = new Datepicker(input);
238
+
239
+ dp.enterEditMode();
240
+ expect(dp.editMode, 'to be undefined');
241
+ expect(input.classList.contains('in-edit'), 'to be false');
242
+
243
+ simulant.fire(input, 'keydown', {key: '1'});
244
+ expect(dp.editMode, 'to be undefined');
245
+
246
+ simulant.fire(input, 'keydown', {key: 'J'});
247
+ expect(dp.editMode, 'to be undefined');
248
+
249
+ simulant.fire(input, 'mousedown');
250
+ input.click();
251
+ expect(dp.editMode, 'to be undefined');
252
+
253
+ dp.destroy();
254
+ });
255
+
256
+ it('disables the arrow-key operation of the picker', function () {
257
+ const clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
258
+ const {dp, picker} = createDP(input);
259
+ const viewSwitch = getViewSwitch(picker);
260
+ input.focus();
261
+ dp.enterEditMode();
262
+
263
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
264
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
265
+
266
+ let cells = getCells(picker);
267
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
268
+ expect(cells[19].textContent, 'to be', '14');
269
+
270
+ simulant.fire(input, 'keydown', {key: 'ArrowRight'});
271
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
272
+ cells = getCells(picker);
273
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
274
+
275
+ simulant.fire(input, 'keydown', {key: 'ArrowUp'});
276
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
277
+ cells = getCells(picker);
278
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
279
+
280
+ simulant.fire(input, 'keydown', {key: 'ArrowDownt'});
281
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
282
+ cells = getCells(picker);
283
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
284
+
285
+ viewSwitch.click();
286
+ simulant.fire(input, 'keydown', {key: 'ArrowLeft'});
287
+ expect(viewSwitch.textContent, 'to be', '2020');
288
+ cells = getCells(picker);
289
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
290
+
291
+ viewSwitch.click();
292
+ simulant.fire(input, 'keydown', {key: 'ArrowRight'});
293
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
294
+ cells = getCells(picker);
295
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
296
+
297
+ viewSwitch.click();
298
+ simulant.fire(input, 'keydown', {key: 'ArrowDown'});
299
+ expect(viewSwitch.textContent, 'to be', '2000-2090');
300
+ cells = getCells(picker);
301
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
302
+
303
+ dp.destroy();
304
+ clock.restore();
305
+ });
306
+
307
+ it('turns off when Datepicker.exitEditMode() is called', function () {
308
+ const dp = new Datepicker(input);
309
+ input.focus();
310
+ dp.enterEditMode();
311
+
312
+ dp.exitEditMode();
313
+ expect(dp.editMode, 'to be undefined');
314
+ expect(input.classList.contains('in-edit'), 'to be false');
315
+
316
+ dp.destroy();
317
+ });
318
+
319
+ it('turns off when the picker hides', function () {
320
+ const {dp, picker} = createDP(input);
321
+ input.focus();
322
+ dp.enterEditMode();
323
+
324
+ dp.hide();
325
+ expect(dp.editMode, 'to be undefined');
326
+ expect(input.classList.contains('in-edit'), 'to be false');
327
+
328
+ dp.destroy();
329
+ });
330
+
331
+ it('turns off when escape key is pressed', function () {
332
+ const dp = new Datepicker(input);
333
+ input.focus();
334
+ dp.enterEditMode();
335
+
336
+ simulant.fire(input, 'keydown', {key: 'Escape'});
337
+ expect(dp.editMode, 'to be undefined');
338
+ expect(input.classList.contains('in-edit'), 'to be false');
339
+
340
+ dp.destroy();
341
+ });
342
+
343
+ it('leaves the edit on the input as-is by default when turning off', function () {
344
+ const dp = new Datepicker(input);
345
+ const date = dateValue(2020, 1, 14);
346
+ dp.setDate(date);
347
+ input.focus();
348
+ dp.enterEditMode();
349
+ input.value = '4/22/2020';
350
+
351
+ dp.exitEditMode();
352
+ expect(input.value, 'to be', '4/22/2020');
353
+ expect(dp.dates, 'to equal', [date]);
354
+
355
+ dp.show();
356
+ dp.enterEditMode();
357
+ input.value = '3/8/2020';
358
+
359
+ dp.hide();
360
+ expect(input.value, 'to be', '3/8/2020');
361
+ expect(dp.dates, 'to equal', [date]);
362
+
363
+ dp.show();
364
+ dp.enterEditMode();
365
+ input.value = '02/14/2020';
366
+
367
+ simulant.fire(input, 'keydown', {key: 'Escape'});
368
+ expect(input.value, 'to be', '02/14/2020');
369
+ expect(dp.dates, 'to equal', [date]);
370
+
371
+ dp.destroy();
372
+ });
373
+
374
+ it('hides the picker when turning off by escape key press', function () {
375
+ const {dp, picker} = createDP(input);
376
+ input.focus();
377
+ dp.enterEditMode();
378
+
379
+ simulant.fire(input, 'keydown', {key: 'Escape'});
380
+ expect(isVisible(picker), 'to be false');
381
+
382
+ dp.show();
383
+ dp.enterEditMode();
384
+
385
+ dp.exitEditMode();
386
+ expect(isVisible(picker), 'to be true');
387
+
388
+ dp.destroy();
389
+ });
390
+
391
+ it('updates the selection with the input when turning off by exitEditMode() call with update: true option', function () {
392
+ const dp = new Datepicker(input);
393
+ const date = dateValue(2020, 3, 22);
394
+ dp.setDate('02/14/2020');
395
+ input.focus();
396
+ dp.enterEditMode();
397
+ input.value = '4/22/2020';
398
+
399
+ dp.exitEditMode({update: true});
400
+ expect(dp.editMode, 'to be undefined');
401
+ expect(input.classList.contains('in-edit'), 'to be false');
402
+ expect(input.value, 'to be', '04/22/2020');
403
+ expect(dp.dates, 'to equal', [date]);
404
+
405
+ dp.destroy();
406
+ });
407
+
408
+ it('updates the selection with the input when turning off by enter key press', function () {
409
+ const dp = new Datepicker(input);
410
+ const date = dateValue(2020, 3, 22);
411
+ dp.setDate('02/14/2020');
412
+ input.focus();
413
+ dp.enterEditMode();
414
+ input.value = '4/22/2020';
415
+
416
+ simulant.fire(input, 'keydown', {key: 'Enter'});
417
+ expect(dp.editMode, 'to be undefined');
418
+ expect(input.classList.contains('in-edit'), 'to be false');
419
+ expect(input.value, 'to be', '04/22/2020');
420
+ expect(dp.dates, 'to equal', [date]);
421
+
422
+ dp.destroy();
423
+ });
424
+
425
+ it('updates the selection with the input when turning off being induced by unfocusing input element', function () {
426
+ const outsider = document.createElement('p');
427
+ testContainer.appendChild(outsider);
428
+
429
+ const dp = new Datepicker(input);
430
+ const date = dateValue(2020, 3, 22);
431
+ // by tab key-press
432
+ dp.setDate('02/14/2020');
433
+ input.focus();
434
+ dp.enterEditMode();
435
+ input.value = '4/22/2020';
436
+
437
+ simulant.fire(input, 'keydown', {key: 'Tab'});
438
+ expect(dp.editMode, 'to be undefined');
439
+ expect(input.classList.contains('in-edit'), 'to be false');
440
+ expect(input.value, 'to be', '04/22/2020');
441
+ expect(dp.dates, 'to equal', [date]);
442
+
443
+ //by clicking outside
444
+ dp.setDate('02/14/2020');
445
+ dp.show();
446
+ dp.enterEditMode();
447
+ input.value = '4/22/2020';
448
+
449
+ simulant.fire(outsider, 'mousedown');
450
+ expect(dp.editMode, 'to be undefined');
451
+ expect(input.classList.contains('in-edit'), 'to be false');
452
+ expect(input.value, 'to be', '04/22/2020');
453
+ expect(dp.dates, 'to equal', [date]);
454
+
455
+ dp.destroy();
456
+ testContainer.removeChild(outsider);
457
+ });
458
+ });
@@ -0,0 +1,146 @@
1
+ describe('keyboard operation', function () {
2
+ let input;
3
+
4
+ beforeEach(function () {
5
+ input = document.createElement('input');
6
+ testContainer.appendChild(input);
7
+ });
8
+
9
+ afterEach(function () {
10
+ testContainer.removeChild(input);
11
+ });
12
+
13
+ describe('tab', function () {
14
+ it('hides the picker', function () {
15
+ const {dp, picker} = createDP(input);
16
+ input.focus();
17
+
18
+ simulant.fire(input, 'keydown', {key: 'Tab'});
19
+ expect(isVisible(picker), 'to be false');
20
+
21
+ dp.destroy();
22
+ });
23
+
24
+ it('updates the selected date with the input\'s value', function () {
25
+ const clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
26
+
27
+ const dp = new Datepicker(input);
28
+ // when picker is shown
29
+ input.focus();
30
+ input.value = 'foo';
31
+
32
+ simulant.fire(input, 'keydown', {key: 'Tab'});
33
+ expect(input.value, 'to be', '02/14/2020');
34
+ expect(dp.getDate().getTime(), 'to be', dateValue(2020, 1, 14));
35
+
36
+ // when picker is hidden
37
+ input.focus();
38
+ input.value = '04/22/2020';
39
+
40
+ simulant.fire(input, 'keydown', {key: 'Tab'});
41
+ expect(input.value, 'to be', '04/22/2020');
42
+ expect(dp.getDate().getTime(), 'to be', dateValue(2020, 3, 22));
43
+
44
+ input.focus();
45
+ input.value = '';
46
+
47
+ simulant.fire(input, 'keydown', {key: 'Tab'});
48
+ expect(input.value, 'to be', '');
49
+ expect(dp.getDate(), 'to be undefined');
50
+
51
+ dp.destroy();
52
+ clock.restore();
53
+ });
54
+ });
55
+
56
+ describe('escape', function () {
57
+ it('shows or hides the picker', function () {
58
+ const {dp, picker} = createDP(input);
59
+
60
+ simulant.fire(input, 'keydown', {key: 'Escape'});
61
+ expect(isVisible(picker), 'to be true');
62
+
63
+ simulant.fire(input, 'keydown', {key: 'Escape'});
64
+ expect(isVisible(picker), 'to be false');
65
+
66
+ dp.destroy();
67
+ });
68
+ });
69
+
70
+ describe('enter', function () {
71
+ it('sets the view date to the selection if the current view is days', function () {
72
+ const clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
73
+ const {dp, picker} = createDP(input);
74
+ input.focus();
75
+
76
+ simulant.fire(input, 'keydown', {key: 'Enter'});
77
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
78
+ expect(input.value, 'to be', '02/14/2020');
79
+
80
+ let cells = getCells(picker);
81
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
82
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
83
+ expect(cells[19].textContent, 'to be', '14');
84
+
85
+ dp.destroy();
86
+ clock.reset();
87
+ });
88
+
89
+ it('changes the view to the next minor one if the current view is not days', function () {
90
+ const clock = sinon.useFakeTimers({now: new Date(2020, 3, 22)});
91
+ const {dp, picker} = createDP(input);
92
+ const viewSwitch = getViewSwitch(picker);
93
+ input.focus();
94
+ viewSwitch.click();
95
+ viewSwitch.click();
96
+ viewSwitch.click();
97
+
98
+ simulant.fire(input, 'keydown', {key: 'Enter'});
99
+ expect(viewSwitch.textContent, 'to be', '2020-2029');
100
+
101
+ let cells = getCells(picker);
102
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[1]]);
103
+ expect(cells[1].textContent, 'to be', '2020');
104
+
105
+ simulant.fire(input, 'keydown', {key: 'Enter'});
106
+ expect(viewSwitch.textContent, 'to be', '2020');
107
+
108
+ cells = getCells(picker);
109
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[3]]);
110
+
111
+ simulant.fire(input, 'keydown', {key: 'Enter'});
112
+ expect(viewSwitch.textContent, 'to be', 'April 2020');
113
+
114
+ cells = getCells(picker);
115
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[24]]);
116
+ expect(cells[24].textContent, 'to be', '22');
117
+
118
+ // does nothig if the view has reached to the min view
119
+ simulant.fire(input, 'keydown', {key: 'Enter'});
120
+ expect(viewSwitch.textContent, 'to be', 'April 2020');
121
+
122
+ dp.destroy();
123
+ clock.reset();
124
+ });
125
+
126
+ it('updates the selection with the input text if the picker is hidden', function () {
127
+ const {dp, picker} = createDP(input);
128
+ const viewSwitch = getViewSwitch(picker);
129
+
130
+ input.value = '7/4/2020';
131
+ simulant.fire(input, 'keydown', {key: 'Enter'});
132
+ expect(dp.dates, 'to equal', [dateValue(2020, 6, 4)]);
133
+ expect(input.value, 'to be', '07/04/2020');
134
+
135
+ dp.show();
136
+ expect(viewSwitch.textContent, 'to be', 'July 2020');
137
+
138
+ let cells = getCells(picker);
139
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[6]]);
140
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[6]]);
141
+ expect(cells[6].textContent, 'to be', '4');
142
+
143
+ dp.destroy();
144
+ });
145
+ });
146
+ });