Skip to content

Commit

Permalink
fix(Card): only capture keys on expandable sections
Browse files Browse the repository at this point in the history
  • Loading branch information
oreqizer committed Nov 10, 2023
1 parent 9081fa2 commit d536470
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from "react";

import RandomIdProvider from "../../OrbitProvider/RandomId/Provider";

import CardSection from ".";

export function CardSectionInput() {
return (
<RandomIdProvider useId={React.useId}>
<CardSection>
<input type="text" data-test="input" />
</CardSection>
</RandomIdProvider>
);
}
16 changes: 16 additions & 0 deletions packages/orbit-components/src/Card/CardSection/CardSection.ct.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from "react";
import { test, expect } from "@playwright/experimental-ct-react";

import { CardSectionInput } from "./CardSection.ct-story";

test.describe("interaction", () => {
test("typing spaces works on non-expandable sections", async ({ mount }) => {
const component = await mount(<CardSectionInput />);
const input = component.getByTestId("input");

await input.focus();
await input.press("Space");

expect(await input.inputValue()).toBe(" ");
});
});
2 changes: 1 addition & 1 deletion packages/orbit-components/src/Card/CardSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function CardSection({
tabIndex={onClick == null ? undefined : 0}
onClick={onClick}
// Not needed once we can use <button> or <a> like we should
onKeyDown={handleKeyDown(onClick)}
onKeyDown={onClick == null ? undefined : handleKeyDown(onClick)}
>
{(title != null || header != null) && expandable && (
<button
Expand Down

0 comments on commit d536470

Please sign in to comment.