Skip to content

Commit 2779136

Browse files
committed
fix(accessibility): accessibility fix
affects: @datepicker-react/hooks, @datepicker-react/styled
1 parent e38801a commit 2779136

File tree

14 files changed

+32999
-34753
lines changed

14 files changed

+32999
-34753
lines changed

packages/hooks/lib/index.cjs.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,13 @@ function useDatepicker(e) {
815815
},
816816
[I, T, D, S],
817817
),
818-
w = react.useCallback(
818+
L = react.useCallback(
819819
function(e) {
820820
return isDateSelected(e, t, a)
821821
},
822822
[t, a],
823823
),
824-
L = react.useCallback(
824+
w = react.useCallback(
825825
function(e) {
826826
return isFirstOrLastSelectedDate(e, t, a)
827827
},
@@ -862,12 +862,16 @@ function useDatepicker(e) {
862862
[p, t, a, c, u, m],
863863
)
864864
function E(e) {
865-
;('ArrowRight' !== e.key &&
866-
'ArrowLeft' !== e.key &&
867-
'ArrowDown' !== e.key &&
868-
'ArrowUp' !== e.key) ||
869-
S ||
870-
(Y(new Date()), T(getInitialMonths(D, new Date())))
865+
if (
866+
('ArrowRight' === e.key ||
867+
'ArrowLeft' === e.key ||
868+
'ArrowDown' === e.key ||
869+
'ArrowUp' === e.key) &&
870+
!S
871+
) {
872+
var t = h[0]
873+
Y(t.date), T(getInitialMonths(D, t.date))
874+
}
871875
}
872876
return (
873877
react.useEffect(function() {
@@ -881,9 +885,9 @@ function useDatepicker(e) {
881885
{
882886
firstDayOfWeek: l,
883887
activeMonths: h,
884-
isDateSelected: w,
888+
isDateSelected: L,
885889
isDateHovered: F,
886-
isFirstOrLastSelectedDate: L,
890+
isFirstOrLastSelectedDate: w,
887891
isDateBlocked: O,
888892
numberOfMonths: D,
889893
isDateFocused: b,
@@ -942,7 +946,7 @@ function useDatepicker(e) {
942946
!u &&
943947
canSelectRange({minBookingDays: c, isDateBlocked: m, startDate: t, endDate: e}) &&
944948
s({startDate: t, endDate: e, focusedInput: null}),
945-
(!S || (S && !is_same_month(e, S))) && T(getInitialMonths(D, e))
949+
r === END_DATE || (S && (!S || is_same_month(e, S))) || T(getInitialMonths(D, e))
946950
},
947951
onDateFocus: Y,
948952
goToPreviousMonths: function() {

packages/hooks/lib/index.esm.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ var o = function(e) {
2222
y = /^-?W(\d{2})$/,
2323
M = /^-?W(\d{2})-?(\d{1})$/,
2424
k = /^(\d{2}([.,]\d*)?)$/,
25-
w = /^(\d{2}):?(\d{2}([.,]\d*)?)$/,
26-
p = /^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,
25+
p = /^(\d{2}):?(\d{2}([.,]\d*)?)$/,
26+
w = /^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,
2727
T = /([Z+-].*)$/,
2828
F = /^(Z)$/,
2929
S = /^([+-])(\d{2})$/,
@@ -98,13 +98,13 @@ var x = function(e, t) {
9898
(A = (function(e) {
9999
var t, n, r
100100
if ((t = k.exec(e))) return ((n = parseFloat(t[1].replace(',', '.'))) % 24) * u
101-
if ((t = w.exec(e)))
101+
if ((t = p.exec(e)))
102102
return (
103103
(n = parseInt(t[1], 10)),
104104
(r = parseFloat(t[2].replace(',', '.'))),
105105
(n % 24) * u + r * i
106106
)
107-
if ((t = p.exec(e))) {
107+
if ((t = w.exec(e))) {
108108
;(n = parseInt(t[1], 10)), (r = parseInt(t[2], 10))
109109
var a = parseFloat(t[3].replace(',', '.'))
110110
return (n % 24) * u + r * i + 1e3 * a
@@ -657,29 +657,29 @@ function ke(e) {
657657
(a && a(t))
658658
)
659659
}
660-
function we(e) {
660+
function pe(e) {
661661
var t = te(e)
662662
return {year: le(t), month: ge(t), date: t}
663663
}
664-
function pe() {
665-
return we(ve())
664+
function we() {
665+
return pe(ve())
666666
}
667667
function Te(e, t) {
668-
var n = t ? we(t) : pe(),
668+
var n = t ? pe(t) : we(),
669669
r = n.date,
670670
a = [n]
671671
return (
672672
e > 1 &&
673673
(a = Array.from(Array(e - 1).keys()).reduce(function(e) {
674-
return (r = he(e[e.length - 1].date, 1)), e.concat([we(r)])
674+
return (r = he(e[e.length - 1].date, 1)), e.concat([pe(r)])
675675
}, a)),
676676
a
677677
)
678678
}
679679
function Fe(e, t, n) {
680680
var r = e[n > 0 ? e.length - 1 : 0].date
681681
return Array.from(Array(t).keys()).reduce(function(e) {
682-
return (r = he(r, n)), n > 0 ? e.concat([we(r)]) : [we(r)].concat(e)
682+
return (r = he(r, n)), n > 0 ? e.concat([pe(r)]) : [pe(r)].concat(e)
683683
}, [])
684684
}
685685
function Se(e, t, n) {
@@ -738,8 +738,8 @@ function Be(e) {
738738
k = t(function() {
739739
return Te(v, a)
740740
}),
741-
w = k[0],
742-
p = k[1],
741+
p = k[0],
742+
w = k[1],
743743
T = t(null),
744744
F = T[0],
745745
S = T[1],
@@ -748,9 +748,9 @@ function Be(e) {
748748
x = Y[1],
749749
B = n(
750750
function(e) {
751-
x(e), (!b || (b && !de(e, b))) && p(Te(v, e))
751+
x(e), (!b || (b && !de(e, b))) && w(Te(v, e))
752752
},
753-
[x, p, v, b],
753+
[x, w, v, b],
754754
),
755755
H = n(
756756
function(e) {
@@ -819,12 +819,16 @@ function Be(e) {
819819
[F, a, o, l, D, M],
820820
)
821821
function L(e) {
822-
;('ArrowRight' !== e.key &&
823-
'ArrowLeft' !== e.key &&
824-
'ArrowDown' !== e.key &&
825-
'ArrowUp' !== e.key) ||
826-
b ||
827-
(B(new Date()), p(Te(v, new Date())))
822+
if (
823+
('ArrowRight' === e.key ||
824+
'ArrowLeft' === e.key ||
825+
'ArrowDown' === e.key ||
826+
'ArrowUp' === e.key) &&
827+
!b
828+
) {
829+
var t = p[0]
830+
B(t.date), w(Te(v, t.date))
831+
}
828832
}
829833
return (
830834
r(function() {
@@ -837,7 +841,7 @@ function Be(e) {
837841
}),
838842
{
839843
firstDayOfWeek: h,
840-
activeMonths: w,
844+
activeMonths: p,
841845
isDateSelected: H,
842846
isDateHovered: W,
843847
isFirstOrLastSelectedDate: I,
@@ -894,14 +898,14 @@ function Be(e) {
894898
!D &&
895899
Ye({minBookingDays: l, isDateBlocked: M, startDate: a, endDate: e}) &&
896900
c({startDate: a, endDate: e, focusedInput: null}),
897-
(!b || (b && !de(e, b))) && p(Te(v, e))
901+
u === xe || (b && (!b || de(e, b))) || w(Te(v, e))
898902
},
899903
onDateFocus: B,
900904
goToPreviousMonths: function() {
901-
p(Fe(w, v, -1)), x(null)
905+
w(Fe(p, v, -1)), x(null)
902906
},
903907
goToNextMonths: function() {
904-
p(Fe(w, v, 1)), x(null)
908+
w(Fe(p, v, 1)), x(null)
905909
},
906910
}
907911
)
@@ -960,8 +964,8 @@ export {
960964
xe as END_DATE,
961965
be as START_DATE,
962966
ae as dayLabelFormat,
963-
pe as getCurrentYearMonthAndDate,
964-
we as getDateMonthAndYear,
967+
we as getCurrentYearMonthAndDate,
968+
pe as getDateMonthAndYear,
965969
re as getDays,
966970
Te as getInitialMonths,
967971
Se as getInputValue,

packages/hooks/src/useDatepicker/useDatepicker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ export function useDatepicker({
133133
e.key === 'ArrowUp') &&
134134
!focusedDate
135135
) {
136-
onDateFocus(new Date())
137-
setActiveMonths(getInitialMonths(numberOfMonths, new Date()))
136+
const activeMonth = activeMonths[0]
137+
onDateFocus(activeMonth.date)
138+
setActiveMonths(getInitialMonths(numberOfMonths, activeMonth.date))
138139
}
139140
}
140141

@@ -221,7 +222,10 @@ export function useDatepicker({
221222
})
222223
}
223224

224-
if (!focusedDate || (focusedDate && !isSameMonth(date, focusedDate))) {
225+
if (
226+
focusedInput !== END_DATE &&
227+
(!focusedDate || (focusedDate && !isSameMonth(date, focusedDate)))
228+
) {
225229
setActiveMonths(getInitialMonths(numberOfMonths, date))
226230
}
227231
}

packages/styled/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ Simple. Use
276276
277277
[LifeOnScreen](https://lifeonscreen.com)
278278
279+
## Articles
280+
281+
[Yet another datepicker in React](https://tresko.dev/yet-another-datepicker-in-react)
282+
279283
## License
280284
281285
Licensed under the MIT License, Copyright © 2019-present Miha Sedej.

0 commit comments

Comments
 (0)