jpmorganchase / salt-ds

React UI components built with a focus on accessibility, customization and ease-of-use
https://www.saltdesignsystem.com
Apache License 2.0
121 stars 88 forks source link

DatePicker Component - Disable Function doesn't work completely #3817

Closed vickybonk closed 2 months ago

vickybonk commented 2 months ago

Package name(s)

Lab (@salt-ds/lab)

Package version(s)

@salt-ds/lab": "1.0.0-alpha.48"

Description

disabled prop with DatePicker isn't completely working properly --> it's disabled when clicking on the calendar icon but still allows an input via the textbox

Steps to reproduce

    <DatePicker
      style={{ width: "200px" }}
      disabled={true}
      onSelectionChange={(event, selectedDate) => {
        if (event.type !== "click") {return;}
        setSchedule(new Date(selectedDate as string));
      }}
      inputProps={{ "aria-label": "schedulePicker" }}
    />

Expected behavior

When testing I expected the DatePicker component to be disabled - but it still allowed input so my test failed

Operating system

Browser

Are you a JPMorgan Chase & Co. employee?

FranklinBarto commented 2 months ago

Hello @vickybonk I do realise your frustration with the textbox, I will share a work around you can use below.

You could disable the textbox by adding an additional props readOnly={true}. In addition to this, you can use the emptyReadOnlyMarker props to then set a placeholder.

<DatePicker
  style={{ width: "200px" }}
  disabled={true}
  readOnly={true}
  emptyReadOnlyMarker={'1-2-2024'}
  onSelectionChange={(event, selectedDate) => {
    if (event.type !== "click") {return;}
    setSchedule(new Date(selectedDate as string));
  }}
  inputProps={{ "aria-label": "schedulePicker" }}
/>
vickybonk commented 2 months ago

thank you!