Skip to content

Commit

Permalink
fix: datepicker year min max
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Jan 15, 2025
1 parent 910bcc4 commit 107ae42
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changeset/tiny-dragons-bow.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
- Add support for `placeholder` context property to customize the input placeholder text.

- Fix issue where entering very large invalid dates in the input field would cause the datepicker to crash.

- Fix issue in year view, where user is unable to select year when `min` and `max` dates are less than 1 year and
overlap 2 unique years
2 changes: 1 addition & 1 deletion examples/next-ts/pages/compositions
5 changes: 2 additions & 3 deletions packages/machines/date-picker/src/date-picker.connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { ariaAttr, dataAttr, getEventKey, getNativeEvent, isComposingEvent } from "@zag-js/dom-query"
import { getPlacementStyles } from "@zag-js/popper"
import type { EventKeyMap, NormalizeProps, PropTypes } from "@zag-js/types"
import { chunk } from "@zag-js/utils"
import { chunk, isValueWithinRange } from "@zag-js/utils"
import { parts } from "./date-picker.anatomy"
import { dom } from "./date-picker.dom"
import type {
Expand Down Expand Up @@ -117,10 +117,9 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize

function getYearTableCellState(props: TableCellProps): TableCellState {
const { value, disabled } = props
const normalized = focusedValue.set({ year: value })
const cellState = {
focused: focusedValue.year === props.value,
selectable: !isDateInvalid(normalized, min, max),
selectable: isValueWithinRange(value, min?.year ?? 0, max?.year ?? 9999),
selected: !!selectedValue.find((date) => date.year === value),
valueText: value.toString(),
get disabled() {
Expand Down

0 comments on commit 107ae42

Please sign in to comment.