diff --git a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.cy.tsx index 1ddccf3b03..84c4b6087c 100644 --- a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.cy.tsx @@ -1,5 +1,4 @@ import { composeStories } from "@storybook/react"; -import { ChangeEvent } from "react"; import * as datePickerStories from "@stories/date-picker/date-picker.stories"; import { checkAccessibility } from "../../../../../../cypress/tests/checkAccessibility"; import { @@ -82,6 +81,11 @@ describe("GIVEN a DatePicker", () => { cy.mount(); cy.findByRole("button").should("be.disabled"); }); + it("THEN render read only when prop is passed", () => { + cy.mount(); + cy.findByRole("textbox").should("have.attr", "readonly"); + cy.findByRole("button").should("be.disabled"); + }); it("THEN it should update the selected month when changing selected date", () => { cy.mount(); cy.findByRole("textbox").click().clear().type(testInput); @@ -95,7 +99,6 @@ describe("GIVEN a DatePicker", () => { cy.mount( ); diff --git a/packages/lab/src/date-input/DateInput.css b/packages/lab/src/date-input/DateInput.css index 95d9c2435f..f1b777411e 100644 --- a/packages/lab/src/date-input/DateInput.css +++ b/packages/lab/src/date-input/DateInput.css @@ -105,7 +105,6 @@ padding: 0; text-align: left; width: min-content; - flex-grow: 1; } /* Reset in the class */ diff --git a/packages/lab/src/date-picker/DatePicker.tsx b/packages/lab/src/date-picker/DatePicker.tsx index d4a04ec5cc..b06cd55e99 100644 --- a/packages/lab/src/date-picker/DatePicker.tsx +++ b/packages/lab/src/date-picker/DatePicker.tsx @@ -15,10 +15,7 @@ import { flip, useDismiss, useInteractions } from "@floating-ui/react"; import { DateInput } from "../date-input"; import { DateValue, getLocalTimeZone, today } from "@internationalized/date"; import { CalendarIcon } from "@salt-ds/icons"; -import { - UseRangeSelectionCalendarProps, - UseSingleSelectionCalendarProps, -} from "../calendar"; +import { CalendarProps } from "../calendar"; const withBaseName = makePrefixer("saltDatePicker"); @@ -55,9 +52,15 @@ export interface DatePickerProps /** * Props to be passed to the Calendar component. */ - CalendarProps?: - | UseRangeSelectionCalendarProps - | UseSingleSelectionCalendarProps; + CalendarProps?: Partial< + Omit< + CalendarProps, + | "selectionVariant" + | "selectedDate" + | "defaultSelectedDate" + | "onSelectedDateChange" + > + >; /** * Function to format the input value. */ @@ -70,6 +73,14 @@ export interface DatePickerProps * Display or hide the component. */ open?: boolean; + /** + * Helper text to display in the panel + */ + helperText?: string; + /** + * If `true`, the component is read only. + */ + readOnly?: boolean; } export const DatePicker = forwardRef( @@ -87,6 +98,8 @@ export const DatePicker = forwardRef( className, open: openProp, onOpenChange: onOpenChangeProp, + helperText, + readOnly: readOnlyProp, ...rest }, ref @@ -142,6 +155,7 @@ export const DatePicker = forwardRef( ]); const { disabled: formFieldDisabled, readOnly: formFieldReadOnly } = useFormFieldProps(); + const isReadOnly = readOnlyProp || formFieldReadOnly; const getPanelPosition = () => ({ top: y ?? 0, @@ -200,11 +214,12 @@ export const DatePicker = forwardRef( endInputRef={endInputRef} placeholder={placeholder} dateFormatter={dateFormatter} + readOnly={isReadOnly} endAdornment={