Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new data-attributes to the day cells #2331

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/__snapshots__/Range.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-05-31"
data-hidden="true"
data-month="2020-05"
data-outside="true"
role="gridcell"
>
<button
Expand Down Expand Up @@ -343,6 +345,7 @@ exports[`should match the snapshot 1`] = `
aria-selected="true"
class="rdp-day rdp-range_start rdp-selected"
data-day="2020-06-15"
data-selected="true"
role="gridcell"
>
<button
Expand All @@ -357,6 +360,7 @@ exports[`should match the snapshot 1`] = `
aria-selected="true"
class="rdp-day rdp-range_middle rdp-selected"
data-day="2020-06-16"
data-selected="true"
role="gridcell"
>
<button
Expand All @@ -371,6 +375,7 @@ exports[`should match the snapshot 1`] = `
aria-selected="true"
class="rdp-day rdp-range_middle rdp-selected"
data-day="2020-06-17"
data-selected="true"
role="gridcell"
>
<button
Expand All @@ -385,6 +390,7 @@ exports[`should match the snapshot 1`] = `
aria-selected="true"
class="rdp-day rdp-range_middle rdp-selected"
data-day="2020-06-18"
data-selected="true"
role="gridcell"
>
<button
Expand All @@ -399,6 +405,7 @@ exports[`should match the snapshot 1`] = `
aria-selected="true"
class="rdp-day rdp-range_end rdp-selected"
data-day="2020-06-19"
data-selected="true"
role="gridcell"
>
<button
Expand Down Expand Up @@ -566,7 +573,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-07-01"
data-hidden="true"
data-month="2020-07"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -581,7 +590,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-07-02"
data-hidden="true"
data-month="2020-07"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -596,7 +607,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-07-03"
data-hidden="true"
data-month="2020-07"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -611,7 +624,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-07-04"
data-hidden="true"
data-month="2020-07"
data-outside="true"
role="gridcell"
>
<button
Expand Down Expand Up @@ -774,7 +789,9 @@ exports[`when a day in the range is clicked when the day is clicked again when a
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-05-31"
data-hidden="true"
data-month="2020-05"
data-outside="true"
role="gridcell"
>
<button
Expand Down Expand Up @@ -1006,6 +1023,7 @@ exports[`when a day in the range is clicked when the day is clicked again when a
<td
class="rdp-day rdp-focused"
data-day="2020-06-17"
data-focused="true"
role="gridcell"
>
<button
Expand Down Expand Up @@ -1199,7 +1217,9 @@ exports[`when a day in the range is clicked when the day is clicked again when a
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-07-01"
data-hidden="true"
data-month="2020-07"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -1214,7 +1234,9 @@ exports[`when a day in the range is clicked when the day is clicked again when a
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-07-02"
data-hidden="true"
data-month="2020-07"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -1229,7 +1251,9 @@ exports[`when a day in the range is clicked when the day is clicked again when a
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-07-03"
data-hidden="true"
data-month="2020-07"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -1244,7 +1268,9 @@ exports[`when a day in the range is clicked when the day is clicked again when a
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2020-07-04"
data-hidden="true"
data-month="2020-07"
data-outside="true"
role="gridcell"
>
<button
Expand Down
11 changes: 11 additions & 0 deletions examples/__snapshots__/StylingCssModules.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2021-10-31"
data-hidden="true"
data-month="2021-10"
data-outside="true"
role="gridcell"
>
<button
Expand Down Expand Up @@ -478,6 +480,7 @@ exports[`should match the snapshot 1`] = `
<td
class="rdp-day rdp-today"
data-day="2021-11-25"
data-today="true"
role="gridcell"
>
<button
Expand Down Expand Up @@ -562,7 +565,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2021-12-01"
data-hidden="true"
data-month="2021-12"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -577,7 +582,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2021-12-02"
data-hidden="true"
data-month="2021-12"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -592,7 +599,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2021-12-03"
data-hidden="true"
data-month="2021-12"
data-outside="true"
role="gridcell"
>
<button
Expand All @@ -607,7 +616,9 @@ exports[`should match the snapshot 1`] = `
aria-hidden="true"
class="rdp-day rdp-hidden rdp-outside"
data-day="2021-12-04"
data-hidden="true"
data-month="2021-12"
data-outside="true"
role="gridcell"
>
<button
Expand Down
19 changes: 12 additions & 7 deletions src/DayPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,6 @@ export function DayPicker(props: DayPickerProps) {
)
: undefined;

const dataAttributes = {
"data-day": dateLib.format(date, "yyyy-MM-dd"),
"data-month": day.outside
? dateLib.format(date, "yyyy-MM")
: undefined
};
return (
<components.Day
key={`${dateLib.format(date, "yyyy-MM-dd")}_${dateLib.format(day.displayMonth, "yyyy-MM")}`}
Expand All @@ -548,7 +542,18 @@ export function DayPicker(props: DayPickerProps) {
aria-hidden={modifiers.hidden || undefined}
aria-selected={modifiers.selected || undefined}
aria-label={ariaLabel}
{...dataAttributes}
data-day={dateLib.format(date, "yyyy-MM-dd")}
data-month={
day.outside
? dateLib.format(date, "yyyy-MM")
: undefined
}
data-selected={modifiers.selected || undefined}
data-disabled={modifiers.disabled || undefined}
data-hidden={modifiers.hidden || undefined}
data-outside={day.outside || undefined}
data-focused={modifiers.focused || undefined}
data-today={modifiers.today || undefined}
>
{isInteractive ? (
<components.DayButton
Expand Down