Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chirokas committed Nov 6, 2024
1 parent b477f74 commit 5bf7332
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .changeset/quick-buses-kick.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
"@nextui-org/select": patch
"@nextui-org/use-aria-multiselect": patch
---

Prevent default browser error UI from appearing.
Prevent default browser error UI from appearing (#3913).
31 changes: 28 additions & 3 deletions packages/components/select/__tests__/select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,13 @@ describe("Select with React Hook Form", () => {
});

describe("validationBehavior=native", () => {
it("should not submit form when required field is empty", async () => {
let user: UserEvent;

beforeEach(() => {
user = userEvent.setup();
});

it("supports server validation", async () => {
const onSubmit = jest.fn();

const {getByTestId} = render(
Expand All @@ -893,6 +899,7 @@ describe("validationBehavior=native", () => {
isRequired
data-testid="select"
label="Test"
name="select"
// validationBehavior="native"
>
<SelectItem key="one">One</SelectItem>
Expand All @@ -905,10 +912,28 @@ describe("validationBehavior=native", () => {
</form>,
);

const user = userEvent.setup();
const button = getByTestId("button");
const select = getByTestId("select");
const input = document.querySelector("[name=select]");

expect(input).toHaveAttribute("required");
expect(select).not.toHaveAttribute("aria-describedby");

await user.click(getByTestId("button"));
await user.click(button);

expect(select).toHaveAttribute("aria-describedby");
expect(input.validity.valid).toBe(false);
expect(onSubmit).toHaveBeenCalledTimes(0);

expect(document.activeElement).toBe(select);

await user.keyboard("[ArrowRight]");

expect(select).not.toHaveAttribute("aria-describedby");
expect(input.validity.valid).toBe(true);

await user.click(button);

expect(onSubmit).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export function useMultiSelectState<T extends {}>(props: MultiSelectProps<T>): M
if (props.selectionMode === "single") {
triggerState.close();
}

validationState.commitValidation();
},
});

Expand Down Expand Up @@ -101,7 +103,6 @@ export function useMultiSelectState<T extends {}>(props: MultiSelectProps<T>): M
if (listState.collection.size !== 0) {
setFocusStrategy(focusStrategy);
triggerState.toggle();
validationState.commitValidation();
}
},
isFocused,
Expand Down

0 comments on commit 5bf7332

Please sign in to comment.