Skip to content

Commit

Permalink
fix: picker: ensure keyboard navigation selected styles are implement…
Browse files Browse the repository at this point in the history
…ed in year mode (#523)
  • Loading branch information
dkilgore-eightfold authored Feb 1, 2023
1 parent 3a29afd commit 3582bc4
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import RangeContext from '../../RangeContext';
import PartialBody from '../PartialBody';
import { DatePickerSize } from '../../OcPicker.types';

import styles from '../../ocpicker.module.scss';

const YEAR_ROW_COUNT: number = 4;

function YearBody<DateType>(props: YearBodyProps<DateType>) {
Expand All @@ -19,18 +21,18 @@ function YearBody<DateType>(props: YearBodyProps<DateType>) {
const { rangedValue, hoverRangedValue } = React.useContext(RangeContext);

const yearNumber: number = generateConfig.getYear(viewDate);
const startYear: number =
const startYearNumber: number =
Math.floor(yearNumber / YEAR_DECADE_COUNT) * YEAR_DECADE_COUNT;
const endYear: number = startYear + YEAR_DECADE_COUNT - 1;
const endYear: number = startYearNumber + YEAR_DECADE_COUNT - 1;
const baseYear: DateType = generateConfig.setYear(
viewDate,
startYear -
startYearNumber -
Math.ceil((YEAR_COL_COUNT * YEAR_ROW_COUNT - YEAR_DECADE_COUNT) / 2)
);

const isInView = (date: DateType): boolean => {
const currentYearNumber: number = generateConfig.getYear(date);
return startYear <= currentYearNumber && currentYearNumber <= endYear;
return startYearNumber <= currentYearNumber && currentYearNumber <= endYear;
};

const getCellClassNames = useCellClassNames<DateType>({
Expand All @@ -43,6 +45,8 @@ function YearBody<DateType>(props: YearBodyProps<DateType>) {
isInView,
offsetCell: (date: DateType, offset: number) =>
generateConfig.addYear(date, offset),
[styles.pickerCellInView]: isInView,
[styles.pickerCellSelected]: startYearNumber === yearNumber,
});

return (
Expand Down

0 comments on commit 3582bc4

Please sign in to comment.