Skip to content

Commit

Permalink
Refactor stepper input (#3976)
Browse files Browse the repository at this point in the history
  • Loading branch information
origami-z authored Sep 30, 2024
1 parent 4ccc245 commit 91639ec
Show file tree
Hide file tree
Showing 12 changed files with 1,138 additions and 403 deletions.
21 changes: 21 additions & 0 deletions .changeset/polite-bags-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@salt-ds/lab": minor
---

## StepperInput updates

- Added `bordered` prop for a full border style
- Changed `StepperInputProps` to extend `div` props instead of `Input`, to align with other input components
- Added an optional event to `onChange`, when triggered by synthetic event
- Added more keyboard interactions, e.g. Shift + Up / Down, Home, End.
- Replaced `block` with `stepBlock` prop, which now explicitly defines the value that is increment or decrement, not a multiplier of `step`.

```tsx
<StepperInput
stepBlock={100}
value={value}
onChange={(_event, value) => {
setValue(value);
}
/>
```
4 changes: 2 additions & 2 deletions docs/components/ResponsiveContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ResponsiveContainer = ({ children }: { children?: ReactNode }) => {
value={containerWidth[0]}
max={maxUnits}
min={10}
onChange={(nextValue) => setWidth([nextValue] as number[])}
onChange={(_event, nextValue) => setWidth([nextValue as number])}
/>
<Slider
className="StoryContainer-slider"
Expand All @@ -45,7 +45,7 @@ export const ResponsiveContainer = ({ children }: { children?: ReactNode }) => {
value={containerHeight[0]}
max={maxUnits}
min={10}
onChange={(nextValue) => setHeight([nextValue] as number[])}
onChange={(_event, nextValue) => setHeight([nextValue as number])}
/>
<Slider
className="StoryContainer-slider"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { FormField, FormFieldHelperText, FormFieldLabel } from "@salt-ds/core";
import { StepperInput } from "@salt-ds/lab";
import * as stepperInputStories from "@stories/stepper-input/stepper-input.stories";
import { composeStories } from "@storybook/react";
import { checkAccessibility } from "../../../../../../cypress/tests/checkAccessibility";

const composedStories = composeStories(stepperInputStories);
const { Default } = composedStories;

describe("Stepper Input - Accessibility", () => {
checkAccessibility(composedStories);

it("sets the correct default ARIA attributes on input", () => {
cy.mount(
<StepperInput
<Default
decimalPlaces={2}
defaultValue={-20.1}
max={250.23}
Expand All @@ -19,28 +25,22 @@ describe("Stepper Input - Accessibility", () => {
});

it("has the correct labelling when wrapped in a `FormField`", () => {
cy.mount(
<FormField>
<FormFieldLabel>Stepper Input</FormFieldLabel>
<StepperInput defaultValue={-10} min={0} />
<FormFieldHelperText>Please enter a value</FormFieldHelperText>
</FormField>,
);
cy.mount(<Default defaultValue={-10} min={0} />);

cy.findByRole("spinbutton").should("have.accessibleName", "Stepper Input");
cy.findByRole("spinbutton").should(
"have.accessibleDescription",
"Please enter a value",
"Please enter a number",
);
});

it("sets `aria-invalid=false` on input when the value is out of range", () => {
cy.mount(<StepperInput defaultValue={-10} min={0} />);
cy.mount(<Default defaultValue={-10} min={0} />);
cy.findByRole("spinbutton").should("have.attr", "aria-invalid", "true");
});

it("sets the correct default ARIA attributes on the increment/decrement buttons", () => {
cy.mount(<StepperInput />);
cy.mount(<Default />);
cy.findByLabelText("increment value")
.should("have.attr", "tabindex", "-1")
.and("have.attr", "aria-hidden", "true");
Expand Down
Loading

0 comments on commit 91639ec

Please sign in to comment.