Skip to content

Commit

Permalink
fix(DatePicker): set type of buttons in CalendarHeader to button inst…
Browse files Browse the repository at this point in the history
…ead of default submit
  • Loading branch information
sxwei123 committed Oct 2, 2024
1 parent 3f2e6d5 commit 54261cc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/DatePicker/CalendarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const CalendarHeader = React.forwardRef<HTMLDivElement, CalendarHeaderProps>(
}
const previousButton = (
<button
type="button"
onClick={handleClickPrevious}
onKeyDown={handlePressPrevious}
aria-label={ariaLabels[view]}
Expand Down Expand Up @@ -194,6 +195,7 @@ const CalendarHeader = React.forwardRef<HTMLDivElement, CalendarHeaderProps>(
}
return (
<button
type="button"
onClick={handleClickNext}
onKeyDown={handlePressNext}
aria-label={ariaLabels[view]}
Expand Down Expand Up @@ -221,6 +223,7 @@ const CalendarHeader = React.forwardRef<HTMLDivElement, CalendarHeaderProps>(

return (
<button
type="button"
onClick={changeView}
onKeyDown={handlePressChangeView}
aria-disabled={view === 'year'}
Expand Down
1 change: 1 addition & 0 deletions src/DatePicker/MonthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export const MonthView = React.forwardRef<HTMLDivElement, MonthViewProps>(
const currentMonthAriaLabel = `Current month, ${defaultAriaLabel}`;
return (
<button
type="button"
aria-label={
isCurrentMonthAndYear ? currentMonthAriaLabel : defaultAriaLabel
}
Expand Down
1 change: 1 addition & 0 deletions src/DatePicker/YearView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export const YearView = React.forwardRef<HTMLDivElement, YearViewProps>(
const isCurrentYear = CURRENT_YEAR === year
return (
<button
type="button"
aria-selected={activeYearClass ? 'true' : 'false'}
aria-label={isCurrentYear ? `Current year, ${year}` : undefined}
className={classNames(
Expand Down
3 changes: 3 additions & 0 deletions tests/DatePicker/__snapshots__/CalendarHeader.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports[`CalendarHeader should have default html structure 1`] = `
>
<button
aria-label="Show previous month"
type="button"
>
<i
class="bi bi-chevron-left"
Expand All @@ -16,11 +17,13 @@ exports[`CalendarHeader should have default html structure 1`] = `
aria-disabled="false"
aria-label=""
aria-live="polite"
type="button"
>
March 2022
</button>
<button
aria-label="Show next month"
type="button"
>
<i
class="bi bi-chevron-right"
Expand Down

0 comments on commit 54261cc

Please sign in to comment.