react-day-picker 8.4.1 → 8.5.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.
- package/dist/index.d.ts +123 -70
- package/dist/index.esm.js +14 -50
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +122 -158
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/style.css +2 -1
- package/dist/style.css.d.ts +38 -37
- package/dist/style.css.map +1 -0
- package/dist/style.module.css +0 -1
- package/dist/style.module.css.d.ts +38 -37
- package/package.json +34 -32
- package/src/DayPicker.tsx +1 -1
- package/src/components/Caption/Caption.test.tsx +2 -2
- package/src/components/CaptionDropdowns/CaptionDropdowns.test.tsx +7 -6
- package/src/components/CaptionLabel/CaptionLabel.test.tsx +1 -1
- package/src/components/CaptionLabel/CaptionLabel.tsx +3 -3
- package/src/components/CaptionNavigation/CaptionNavigation.test.tsx +11 -10
- package/src/components/CaptionNavigation/CaptionNavigation.tsx +1 -1
- package/src/components/Day/Day.test.tsx +15 -16
- package/src/components/Day/Day.tsx +1 -1
- package/src/components/DayContent/DayContent.test.tsx +1 -1
- package/src/components/Footer/Footer.test.tsx +1 -1
- package/src/components/HeadRow/HeadRow.test.tsx +1 -20
- package/src/components/HeadRow/HeadRow.tsx +2 -6
- package/src/components/HeadRow/utils/getWeekdays.test.ts +1 -1
- package/src/components/HeadRow/utils/getWeekdays.ts +1 -5
- package/src/components/Month/Month.test.tsx +1 -1
- package/src/components/MonthsDropdown/MonthsDropdown.test.tsx +3 -2
- package/src/components/MonthsDropdown/MonthsDropdown.tsx +1 -3
- package/src/components/Navigation/Navigation.test.tsx +10 -9
- package/src/components/Root/Root.test.tsx +2 -3
- package/src/components/Row/Row.tsx +2 -1
- package/src/components/Table/Table.tsx +1 -1
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +219 -210
- package/src/components/Table/utils/daysToMonthWeeks.ts +11 -10
- package/src/components/Table/utils/getMonthWeeks.ts +7 -6
- package/src/components/YearsDropdown/YearsDropdown.test.tsx +3 -2
- package/src/components/YearsDropdown/YearsDropdown.tsx +1 -3
- package/src/contexts/DayPicker/DayPickerContext.test.ts +55 -138
- package/src/contexts/DayPicker/defaultContextValues.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatCaption.test.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatCaption.ts +1 -2
- package/src/contexts/DayPicker/formatters/formatDay.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatMonthCaption.test.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatMonthCaption.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatWeekdayName.test.ts +3 -3
- package/src/contexts/DayPicker/formatters/formatWeekdayName.ts +2 -2
- package/src/contexts/DayPicker/formatters/formatYearCaption.ts +1 -1
- package/src/contexts/DayPicker/labels/labelDay.ts +1 -1
- package/src/contexts/DayPicker/labels/labelWeekday.test.ts +1 -1
- package/src/contexts/DayPicker/labels/labelWeekday.ts +1 -1
- package/src/contexts/DayPicker/utils/parseFromToProps.ts +1 -3
- package/src/contexts/Focus/FocusContext.test.ts +35 -62
- package/src/contexts/Focus/FocusContext.tsx +1 -1
- package/src/contexts/Focus/utils/getInitialFocusTarget.ts +1 -3
- package/src/contexts/Focus/utils/getNextFocus.ts +12 -10
- package/src/contexts/Modifiers/ModifiersContext.test.ts +8 -14
- package/src/contexts/Modifiers/utils/getActiveModifiers.ts +1 -1
- package/src/contexts/Modifiers/utils/isDateInRange.ts +1 -2
- package/src/contexts/Modifiers/utils/isMatch.ts +1 -4
- package/src/contexts/Navigation/NavigationContext.test.ts +12 -17
- package/src/contexts/Navigation/NavigationContext.tsx +1 -3
- package/src/contexts/Navigation/useNavigationState.test.ts +9 -16
- package/src/contexts/Navigation/useNavigationState.ts +6 -4
- package/src/contexts/Navigation/utils/getDisplayMonths.ts +1 -3
- package/src/contexts/Navigation/utils/getInitialMonth.ts +1 -3
- package/src/contexts/Navigation/utils/getNextMonth.ts +1 -3
- package/src/contexts/Navigation/utils/getPreviousMonth.ts +1 -3
- package/src/contexts/SelectMultiple/SelectMultipleContext.test.ts +15 -20
- package/src/contexts/SelectMultiple/SelectMultipleContext.tsx +1 -1
- package/src/contexts/SelectRange/SelectRangeContext.test.ts +23 -29
- package/src/contexts/SelectRange/SelectRangeContext.tsx +6 -4
- package/src/contexts/SelectRange/utils/addToRange.ts +1 -3
- package/src/contexts/SelectSingle/SelectSingleContext.test.ts +18 -15
- package/src/hooks/useActiveModifiers/useActiveModifiers.test.tsx +9 -16
- package/src/hooks/useControlledValue/useControlledValue.test.ts +16 -39
- package/src/hooks/useDayEventHandlers/useDayEventHandlers.test.tsx +18 -78
- package/src/hooks/useDayRender/useDayRender.test.tsx +68 -95
- package/src/hooks/useDayRender/useDayRender.tsx +5 -8
- package/src/hooks/useInput/useInput.ts +2 -4
- package/src/hooks/useSelectedDays/useSelectedDays.test.ts +15 -45
- package/src/index.ts +1 -0
- package/src/style.css +0 -1
- package/src/style.css.d.ts +37 -36
- package/src/types/Labels.ts +1 -0
- package/dist/index.esm.d.ts +0 -1175
- package/dist/react-day-picker.min.js +0 -1
|
@@ -1,77 +1,65 @@
|
|
|
1
1
|
import { createRef } from 'react';
|
|
2
2
|
|
|
3
|
-
import { RenderResult } from '@testing-library/react-hooks';
|
|
4
3
|
import { addDays, addMonths } from 'date-fns';
|
|
5
4
|
import { DayPickerProps } from 'DayPicker';
|
|
6
5
|
|
|
7
|
-
import {
|
|
6
|
+
import { mockedContexts } from 'test/mockedContexts';
|
|
7
|
+
import { renderDayPickerHook } from 'test/render';
|
|
8
8
|
import { freezeBeforeAll } from 'test/utils';
|
|
9
9
|
|
|
10
10
|
import { defaultClassNames } from 'contexts/DayPicker/defaultClassNames';
|
|
11
11
|
import { FocusContextValue } from 'contexts/Focus';
|
|
12
|
+
import { SelectMultipleContextValue } from 'contexts/SelectMultiple';
|
|
13
|
+
import { SelectRangeContextValue } from 'contexts/SelectRange';
|
|
14
|
+
import { SelectSingleContextValue } from 'contexts/SelectSingle';
|
|
12
15
|
import { EventName } from 'hooks/useDayEventHandlers';
|
|
13
16
|
|
|
14
|
-
import { DayRender } from './';
|
|
15
17
|
import { useDayRender } from './useDayRender';
|
|
16
18
|
|
|
17
19
|
const today = new Date(2022, 5, 13);
|
|
18
20
|
|
|
19
21
|
freezeBeforeAll(today);
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const mockedFocusContext: FocusContextValue = {
|
|
24
|
-
focus: jest.fn(),
|
|
25
|
-
focusedDay: undefined,
|
|
26
|
-
focusTarget: undefined,
|
|
27
|
-
blur: jest.fn(),
|
|
28
|
-
focusDayAfter: jest.fn(),
|
|
29
|
-
focusDayBefore: jest.fn(),
|
|
30
|
-
focusWeekBefore: jest.fn(),
|
|
31
|
-
focusWeekAfter: jest.fn(),
|
|
32
|
-
focusMonthBefore: jest.fn(),
|
|
33
|
-
focusMonthAfter: jest.fn(),
|
|
34
|
-
focusYearBefore: jest.fn(),
|
|
35
|
-
focusYearAfter: jest.fn(),
|
|
36
|
-
focusStartOfWeek: jest.fn(),
|
|
37
|
-
focusEndOfWeek: jest.fn()
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
function setup(
|
|
23
|
+
function renderHook(
|
|
41
24
|
date: Date,
|
|
42
25
|
displayMonth: Date,
|
|
43
26
|
dayPickerProps?: DayPickerProps,
|
|
44
|
-
contexts?:
|
|
27
|
+
contexts?: {
|
|
28
|
+
single: SelectSingleContextValue;
|
|
29
|
+
multiple: SelectMultipleContextValue;
|
|
30
|
+
range: SelectRangeContextValue;
|
|
31
|
+
focus: FocusContextValue;
|
|
32
|
+
}
|
|
45
33
|
) {
|
|
46
34
|
const buttonRef = createRef<HTMLButtonElement>();
|
|
47
|
-
|
|
35
|
+
return renderDayPickerHook(
|
|
48
36
|
() => useDayRender(date, displayMonth, buttonRef),
|
|
49
37
|
dayPickerProps,
|
|
50
38
|
contexts
|
|
51
39
|
);
|
|
52
|
-
result = view.result;
|
|
53
40
|
}
|
|
54
41
|
|
|
55
42
|
describe('when rendering the today’s date', () => {
|
|
56
43
|
const date = today;
|
|
57
44
|
const displayMonth = date;
|
|
58
|
-
beforeEach(() => {
|
|
59
|
-
setup(date, displayMonth);
|
|
60
|
-
});
|
|
61
45
|
test('the div should include the default class name', () => {
|
|
46
|
+
const result = renderHook(date, displayMonth);
|
|
62
47
|
expect(result.current.divProps.className?.split(' ')).toContain(
|
|
63
48
|
defaultClassNames.day
|
|
64
49
|
);
|
|
65
50
|
});
|
|
66
51
|
test('the button should include the default class name', () => {
|
|
52
|
+
const result = renderHook(date, displayMonth);
|
|
67
53
|
expect(result.current.buttonProps.className?.split(' ')).toContain(
|
|
68
54
|
defaultClassNames.day
|
|
69
55
|
);
|
|
70
56
|
});
|
|
71
|
-
test('the button should not have "aria-
|
|
72
|
-
|
|
57
|
+
test('the button should not have "aria-selected"', () => {
|
|
58
|
+
const result = renderHook(date, displayMonth);
|
|
59
|
+
expect(result.current.buttonProps['aria-selected']).toBeUndefined();
|
|
73
60
|
});
|
|
74
61
|
test('the button should have 0 as "tabIndex"', () => {
|
|
62
|
+
const result = renderHook(date, displayMonth);
|
|
75
63
|
expect(result.current.buttonProps.tabIndex).toBe(0);
|
|
76
64
|
});
|
|
77
65
|
|
|
@@ -91,48 +79,42 @@ describe('when rendering the today’s date', () => {
|
|
|
91
79
|
test.each(testEvents)(
|
|
92
80
|
'the button should have the "%s" event handler',
|
|
93
81
|
(eventName) => {
|
|
82
|
+
const result = renderHook(date, displayMonth);
|
|
94
83
|
expect(result.current.buttonProps[eventName]).toBeDefined();
|
|
95
84
|
}
|
|
96
85
|
);
|
|
97
86
|
test('should return the day active modifiers', () => {
|
|
87
|
+
const result = renderHook(date, displayMonth);
|
|
98
88
|
expect(result.current.activeModifiers).toEqual({ today: true });
|
|
99
89
|
});
|
|
100
90
|
});
|
|
101
91
|
|
|
102
92
|
describe('when not in selection mode', () => {
|
|
103
93
|
const dayPickerProps = { mode: undefined };
|
|
104
|
-
beforeEach(() => {
|
|
105
|
-
setup(today, today, dayPickerProps);
|
|
106
|
-
});
|
|
107
94
|
test('should not be a button', () => {
|
|
95
|
+
const result = renderHook(today, today, dayPickerProps);
|
|
108
96
|
expect(result.current.isButton).toBe(false);
|
|
109
97
|
});
|
|
110
98
|
});
|
|
111
99
|
describe('when "onDayClick" is not passed in', () => {
|
|
112
100
|
const dayPickerProps = { onDayClick: undefined };
|
|
113
|
-
beforeEach(() => {
|
|
114
|
-
setup(today, today, dayPickerProps);
|
|
115
|
-
});
|
|
116
101
|
test('should not be a button', () => {
|
|
102
|
+
const result = renderHook(today, today, dayPickerProps);
|
|
117
103
|
expect(result.current.isButton).toBe(false);
|
|
118
104
|
});
|
|
119
105
|
});
|
|
120
106
|
describe('when in selection mode', () => {
|
|
121
107
|
const dayPickerProps: DayPickerProps = { mode: 'single' };
|
|
122
|
-
beforeEach(() => {
|
|
123
|
-
setup(today, today, dayPickerProps);
|
|
124
|
-
});
|
|
125
108
|
test('should be a button', () => {
|
|
109
|
+
const result = renderHook(today, today, dayPickerProps);
|
|
126
110
|
expect(result.current.isButton).toBe(true);
|
|
127
111
|
});
|
|
128
112
|
});
|
|
129
113
|
|
|
130
114
|
describe('when "onDayClick" is passed in', () => {
|
|
131
115
|
const dayPickerProps: DayPickerProps = { onDayClick: jest.fn() };
|
|
132
|
-
beforeEach(() => {
|
|
133
|
-
setup(today, today, dayPickerProps);
|
|
134
|
-
});
|
|
135
116
|
test('should be a button', () => {
|
|
117
|
+
const result = renderHook(today, today, dayPickerProps);
|
|
136
118
|
expect(result.current.isButton).toBe(true);
|
|
137
119
|
});
|
|
138
120
|
});
|
|
@@ -142,10 +124,8 @@ describe('when showing the outside days', () => {
|
|
|
142
124
|
describe('when the day is outside', () => {
|
|
143
125
|
const day = today;
|
|
144
126
|
const displayMonth = addMonths(today, 1);
|
|
145
|
-
beforeEach(() => {
|
|
146
|
-
setup(day, displayMonth, dayPickerProps);
|
|
147
|
-
});
|
|
148
127
|
test('should be hidden', () => {
|
|
128
|
+
const result = renderHook(day, displayMonth, dayPickerProps);
|
|
149
129
|
expect(result.current.isHidden).toBe(true);
|
|
150
130
|
});
|
|
151
131
|
});
|
|
@@ -156,13 +136,12 @@ describe('when the day has the "hidden" modifier active', () => {
|
|
|
156
136
|
const dayPickerProps: DayPickerProps = {
|
|
157
137
|
modifiers: { hidden: date }
|
|
158
138
|
};
|
|
159
|
-
beforeEach(() => {
|
|
160
|
-
setup(date, date, dayPickerProps);
|
|
161
|
-
});
|
|
162
139
|
test('should have the hidden modifier active', () => {
|
|
140
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
163
141
|
expect(result.current.activeModifiers.hidden).toBe(true);
|
|
164
142
|
});
|
|
165
143
|
test('should be hidden', () => {
|
|
144
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
166
145
|
expect(result.current.isHidden).toBe(true);
|
|
167
146
|
});
|
|
168
147
|
});
|
|
@@ -173,15 +152,14 @@ describe('when "modifiersStyles" is passed in', () => {
|
|
|
173
152
|
modifiers: { foo: date },
|
|
174
153
|
modifiersStyles: { foo: { color: 'red' } }
|
|
175
154
|
};
|
|
176
|
-
beforeEach(() => {
|
|
177
|
-
setup(date, date, dayPickerProps);
|
|
178
|
-
});
|
|
179
155
|
test('the div props should include the modifiers style', () => {
|
|
156
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
180
157
|
expect(result.current.divProps.style).toStrictEqual(
|
|
181
158
|
dayPickerProps.modifiersStyles.foo
|
|
182
159
|
);
|
|
183
160
|
});
|
|
184
161
|
test('the button props should include the modifiers style', () => {
|
|
162
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
185
163
|
expect(result.current.buttonProps.style).toStrictEqual(
|
|
186
164
|
dayPickerProps.modifiersStyles.foo
|
|
187
165
|
);
|
|
@@ -192,15 +170,14 @@ describe('when "styles.day" is passed in', () => {
|
|
|
192
170
|
const dayPickerProps = {
|
|
193
171
|
styles: { day: { color: 'red' } }
|
|
194
172
|
};
|
|
195
|
-
beforeEach(() => {
|
|
196
|
-
setup(date, date, dayPickerProps);
|
|
197
|
-
});
|
|
198
173
|
test('the div props should include the style', () => {
|
|
174
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
199
175
|
expect(result.current.divProps.style).toStrictEqual(
|
|
200
176
|
dayPickerProps.styles.day
|
|
201
177
|
);
|
|
202
178
|
});
|
|
203
179
|
test('the button props should include the style', () => {
|
|
180
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
204
181
|
expect(result.current.buttonProps.style).toStrictEqual(
|
|
205
182
|
dayPickerProps.styles.day
|
|
206
183
|
);
|
|
@@ -213,9 +190,7 @@ describe('when "modifiersClassNames" is passed in', () => {
|
|
|
213
190
|
modifiers: { foo: date },
|
|
214
191
|
modifiersClassNames: { foo: 'bar' }
|
|
215
192
|
};
|
|
216
|
-
|
|
217
|
-
setup(date, date, dayPickerProps);
|
|
218
|
-
});
|
|
193
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
219
194
|
test('the div props should include the modifiers classNames', () => {
|
|
220
195
|
expect(result.current.divProps.className).toContain(
|
|
221
196
|
dayPickerProps.modifiersClassNames.foo
|
|
@@ -233,9 +208,7 @@ describe('when "classNames.day" is passed in', () => {
|
|
|
233
208
|
const dayPickerProps = {
|
|
234
209
|
classNames: { day: 'foo' }
|
|
235
210
|
};
|
|
236
|
-
|
|
237
|
-
setup(date, date, dayPickerProps);
|
|
238
|
-
});
|
|
211
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
239
212
|
test('the div props should include the class name', () => {
|
|
240
213
|
expect(result.current.divProps.className).toContain(
|
|
241
214
|
dayPickerProps.classNames.day
|
|
@@ -252,12 +225,15 @@ describe('when the day is not target of focus', () => {
|
|
|
252
225
|
const yesterday = addDays(today, -1);
|
|
253
226
|
const tomorrow = addDays(today, 1);
|
|
254
227
|
const focusContext: FocusContextValue = {
|
|
255
|
-
...
|
|
228
|
+
...mockedContexts.focus,
|
|
256
229
|
focusTarget: yesterday
|
|
257
230
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
231
|
+
const result = renderHook(
|
|
232
|
+
tomorrow,
|
|
233
|
+
tomorrow,
|
|
234
|
+
{},
|
|
235
|
+
{ ...mockedContexts, focus: focusContext }
|
|
236
|
+
);
|
|
261
237
|
test('the button should have tabIndex -1', () => {
|
|
262
238
|
expect(result.current.buttonProps.tabIndex).toBe(-1);
|
|
263
239
|
});
|
|
@@ -266,12 +242,15 @@ describe('when the day is not target of focus', () => {
|
|
|
266
242
|
describe('when the day is target of focus', () => {
|
|
267
243
|
const date = today;
|
|
268
244
|
const focusContext: FocusContextValue = {
|
|
269
|
-
...
|
|
245
|
+
...mockedContexts.focus,
|
|
270
246
|
focusTarget: date
|
|
271
247
|
};
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
248
|
+
const result = renderHook(
|
|
249
|
+
date,
|
|
250
|
+
date,
|
|
251
|
+
{},
|
|
252
|
+
{ ...mockedContexts, focus: focusContext }
|
|
253
|
+
);
|
|
275
254
|
test('the button should have tabIndex 0', () => {
|
|
276
255
|
expect(result.current.buttonProps.tabIndex).toBe(0);
|
|
277
256
|
});
|
|
@@ -280,17 +259,15 @@ describe('when the day is target of focus', () => {
|
|
|
280
259
|
describe('when the day is target of focus but outside', () => {
|
|
281
260
|
const date = today;
|
|
282
261
|
const focusContext: FocusContextValue = {
|
|
283
|
-
...
|
|
262
|
+
...mockedContexts.focus,
|
|
284
263
|
focusTarget: date
|
|
285
264
|
};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
);
|
|
293
|
-
});
|
|
265
|
+
const result = renderHook(
|
|
266
|
+
date,
|
|
267
|
+
date,
|
|
268
|
+
{ modifiers: { outside: date } },
|
|
269
|
+
{ ...mockedContexts, focus: focusContext }
|
|
270
|
+
);
|
|
294
271
|
test('the button should have tabIndex -1', () => {
|
|
295
272
|
expect(result.current.buttonProps.tabIndex).toBe(-1);
|
|
296
273
|
});
|
|
@@ -299,12 +276,16 @@ describe('when the day is target of focus but outside', () => {
|
|
|
299
276
|
describe('when the day is focused', () => {
|
|
300
277
|
const date = today;
|
|
301
278
|
const focusContext: FocusContextValue = {
|
|
302
|
-
...
|
|
279
|
+
...mockedContexts.focus,
|
|
303
280
|
focusedDay: date
|
|
304
281
|
};
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
282
|
+
const result = renderHook(
|
|
283
|
+
date,
|
|
284
|
+
date,
|
|
285
|
+
{},
|
|
286
|
+
{ ...mockedContexts, focus: focusContext }
|
|
287
|
+
);
|
|
288
|
+
|
|
308
289
|
test('the button should have tabIndex 0', () => {
|
|
309
290
|
expect(result.current.buttonProps.tabIndex).toBe(0);
|
|
310
291
|
});
|
|
@@ -312,12 +293,8 @@ describe('when the day is focused', () => {
|
|
|
312
293
|
|
|
313
294
|
describe('when the day is disabled', () => {
|
|
314
295
|
const date = today;
|
|
315
|
-
const dayPickerProps = {
|
|
316
|
-
|
|
317
|
-
};
|
|
318
|
-
beforeEach(() => {
|
|
319
|
-
setup(date, date, dayPickerProps);
|
|
320
|
-
});
|
|
296
|
+
const dayPickerProps = { disabled: date };
|
|
297
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
321
298
|
test('the button should be disabled', () => {
|
|
322
299
|
expect(result.current.buttonProps.disabled).toBe(true);
|
|
323
300
|
});
|
|
@@ -325,13 +302,9 @@ describe('when the day is disabled', () => {
|
|
|
325
302
|
|
|
326
303
|
describe('when the day is selected', () => {
|
|
327
304
|
const date = today;
|
|
328
|
-
const dayPickerProps = {
|
|
329
|
-
|
|
330
|
-
};
|
|
331
|
-
beforeEach(() => {
|
|
332
|
-
setup(date, date, dayPickerProps);
|
|
333
|
-
});
|
|
305
|
+
const dayPickerProps = { selected: date };
|
|
306
|
+
const result = renderHook(date, date, dayPickerProps);
|
|
334
307
|
test('the button should have "aria-pressed"', () => {
|
|
335
|
-
expect(result.current.buttonProps['aria-
|
|
308
|
+
expect(result.current.buttonProps['aria-selected']).toBe(true);
|
|
336
309
|
});
|
|
337
310
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
|
|
3
|
-
import isSameDay from 'date-fns
|
|
3
|
+
import { isSameDay } from 'date-fns';
|
|
4
4
|
|
|
5
5
|
import { ButtonProps } from 'components/Button';
|
|
6
6
|
import { DayContent } from 'components/DayContent';
|
|
@@ -27,7 +27,7 @@ export type DayRender = {
|
|
|
27
27
|
activeModifiers: ActiveModifiers;
|
|
28
28
|
/** The props to apply to the button element (when `isButton` is true). */
|
|
29
29
|
buttonProps: StyledComponent &
|
|
30
|
-
Pick<ButtonProps, 'disabled' | 'aria-
|
|
30
|
+
Pick<ButtonProps, 'disabled' | 'aria-selected' | 'tabIndex'> &
|
|
31
31
|
DayEventHandlers;
|
|
32
32
|
/** The props to apply to the div element (when `isButton` is false). */
|
|
33
33
|
divProps: StyledComponent;
|
|
@@ -75,9 +75,6 @@ export function useDayRender(
|
|
|
75
75
|
|
|
76
76
|
const className = getDayClassNames(dayPicker, activeModifiers).join(' ');
|
|
77
77
|
const style = getDayStyle(dayPicker, activeModifiers);
|
|
78
|
-
const ariaLabel = dayPicker.labels.labelDay(day, activeModifiers, {
|
|
79
|
-
locale: dayPicker.locale
|
|
80
|
-
});
|
|
81
78
|
const isHidden = Boolean(
|
|
82
79
|
(activeModifiers.outside && !dayPicker.showOutsideDays) ||
|
|
83
80
|
activeModifiers.hidden
|
|
@@ -96,7 +93,7 @@ export function useDayRender(
|
|
|
96
93
|
style,
|
|
97
94
|
className,
|
|
98
95
|
children,
|
|
99
|
-
'
|
|
96
|
+
role: 'gridcell'
|
|
100
97
|
};
|
|
101
98
|
|
|
102
99
|
const isFocusTarget =
|
|
@@ -110,8 +107,8 @@ export function useDayRender(
|
|
|
110
107
|
const buttonProps = {
|
|
111
108
|
...divProps,
|
|
112
109
|
disabled: activeModifiers.disabled,
|
|
113
|
-
|
|
114
|
-
['aria-
|
|
110
|
+
role: 'gridcell',
|
|
111
|
+
['aria-selected']: activeModifiers.selected,
|
|
115
112
|
tabIndex: isFocused || isFocusTarget ? 0 : -1,
|
|
116
113
|
...eventHandlers
|
|
117
114
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
|
|
3
|
-
import differenceInCalendarDays from 'date-fns
|
|
4
|
-
import
|
|
5
|
-
import enUS from 'date-fns/locale/en-US';
|
|
6
|
-
import parse from 'date-fns/parse';
|
|
3
|
+
import { differenceInCalendarDays, format as _format, parse } from 'date-fns';
|
|
4
|
+
import { enUS } from 'date-fns/locale';
|
|
7
5
|
|
|
8
6
|
import { parseFromToProps } from 'contexts/DayPicker/utils';
|
|
9
7
|
import { DayPickerBase } from 'types/DayPickerBase';
|
|
@@ -1,72 +1,42 @@
|
|
|
1
|
-
import { RenderResult } from '@testing-library/react-hooks';
|
|
2
1
|
import { DayPickerProps } from 'DayPicker';
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { mockedContexts } from 'test/mockedContexts';
|
|
4
|
+
import { renderDayPickerHook } from 'test/render';
|
|
5
|
+
import { freezeBeforeAll } from 'test/utils';
|
|
5
6
|
|
|
6
|
-
import {
|
|
7
|
-
import { SelectRangeContextValue } from 'contexts/SelectRange';
|
|
8
|
-
import { SelectSingleContextValue } from 'contexts/SelectSingle';
|
|
9
|
-
|
|
10
|
-
import { SelectedDays, useSelectedDays } from './useSelectedDays';
|
|
7
|
+
import { useSelectedDays } from './useSelectedDays';
|
|
11
8
|
|
|
12
9
|
const today = new Date(2021, 11, 8);
|
|
10
|
+
freezeBeforeAll(today);
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const multiple: SelectMultipleContextValue = {
|
|
19
|
-
selected: [today],
|
|
20
|
-
modifiers: { disabled: [] }
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const range: SelectRangeContextValue = {
|
|
24
|
-
selected: undefined,
|
|
25
|
-
modifiers: {
|
|
26
|
-
disabled: [],
|
|
27
|
-
range_start: [],
|
|
28
|
-
range_end: [],
|
|
29
|
-
range_middle: []
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const selectionContext = { single, multiple, range };
|
|
33
|
-
|
|
34
|
-
let renderResult: RenderResult<SelectedDays>;
|
|
35
|
-
function setup(dayPickerProps: DayPickerProps) {
|
|
36
|
-
const view = customRenderHook(
|
|
37
|
-
useSelectedDays,
|
|
12
|
+
function renderHook(dayPickerProps: DayPickerProps) {
|
|
13
|
+
return renderDayPickerHook(
|
|
14
|
+
() => useSelectedDays(),
|
|
38
15
|
dayPickerProps,
|
|
39
|
-
|
|
16
|
+
mockedContexts
|
|
40
17
|
);
|
|
41
|
-
renderResult = view.result;
|
|
42
18
|
}
|
|
43
19
|
|
|
44
20
|
describe('when in single selection mode', () => {
|
|
45
21
|
const mode = 'single';
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
setup({ mode });
|
|
48
|
-
});
|
|
49
22
|
test('should return the selection from the single context', () => {
|
|
50
|
-
|
|
23
|
+
const result = renderHook({ mode, selected: today });
|
|
24
|
+
expect(result.current).toBe(mockedContexts.single.selected);
|
|
51
25
|
});
|
|
52
26
|
});
|
|
53
27
|
|
|
54
28
|
describe('when in multiple selection mode', () => {
|
|
55
29
|
const mode = 'multiple';
|
|
56
|
-
beforeEach(() => {
|
|
57
|
-
setup({ mode });
|
|
58
|
-
});
|
|
59
30
|
test('should return the selection from the multiple context', () => {
|
|
60
|
-
|
|
31
|
+
const result = renderHook({ mode });
|
|
32
|
+
expect(result.current).toBe(mockedContexts.multiple.selected);
|
|
61
33
|
});
|
|
62
34
|
});
|
|
63
35
|
|
|
64
36
|
describe('when in range selection mode', () => {
|
|
65
37
|
const mode = 'range';
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
setup({ mode });
|
|
68
|
-
});
|
|
69
38
|
test('should return the selection from the range context', () => {
|
|
70
|
-
|
|
39
|
+
const result = renderHook({ mode });
|
|
40
|
+
expect(result.current).toBe(mockedContexts.range.selected);
|
|
71
41
|
});
|
|
72
42
|
});
|
package/src/index.ts
CHANGED
package/src/style.css
CHANGED
package/src/style.css.d.ts
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
declare const styles: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
rdp: string;
|
|
3
|
+
'rdp-vhidden': string;
|
|
4
|
+
'rdp-button_reset': string;
|
|
5
|
+
'rdp-button': string;
|
|
6
|
+
'rdp-day_selected': string;
|
|
7
|
+
'rdp-months': string;
|
|
8
|
+
'rdp-month': string;
|
|
9
|
+
'rdp-table': string;
|
|
10
|
+
'rdp-with_weeknumber': string;
|
|
11
|
+
'rdp-caption': string;
|
|
12
|
+
'rdp-multiple_months': string;
|
|
13
|
+
'rdp-caption_dropdowns': string;
|
|
14
|
+
'rdp-caption_label': string;
|
|
15
|
+
'rdp-nav': string;
|
|
16
|
+
'rdp-caption_start': string;
|
|
17
|
+
'rdp-caption_end': string;
|
|
18
|
+
'rdp-nav_button': string;
|
|
19
|
+
'rdp-dropdown_year': string;
|
|
20
|
+
'rdp-dropdown_month': string;
|
|
21
|
+
'rdp-dropdown': string;
|
|
22
|
+
'rdp-dropdown_icon': string;
|
|
23
|
+
'rdp-head': string;
|
|
24
|
+
'rdp-head_row': string;
|
|
25
|
+
'rdp-row': string;
|
|
26
|
+
'rdp-head_cell': string;
|
|
27
|
+
'rdp-tbody': string;
|
|
28
|
+
'rdp-tfoot': string;
|
|
29
|
+
'rdp-cell': string;
|
|
30
|
+
'rdp-weeknumber': string;
|
|
31
|
+
'rdp-day': string;
|
|
32
|
+
'rdp-day_today': string;
|
|
33
|
+
'rdp-day_outside': string;
|
|
34
|
+
'rdp-day_range_start': string;
|
|
35
|
+
'rdp-day_range_end': string;
|
|
36
|
+
'rdp-day_range_middle': string;
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
export default styles;
|
package/src/types/Labels.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type Labels = {
|
|
|
8
8
|
labelYearDropdown: () => string;
|
|
9
9
|
labelNext: NavButtonLabel;
|
|
10
10
|
labelPrevious: NavButtonLabel;
|
|
11
|
+
/** @deprecated This label is not used anymore and this function will be removed in the future. */
|
|
11
12
|
labelDay: DayLabel;
|
|
12
13
|
labelWeekday: WeekdayLabel;
|
|
13
14
|
labelWeekNumber: WeekNumberLabel;
|