Skip to content

Commit

Permalink
fix(Input): don't stop propagation of keyboard events
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezamirian committed Dec 9, 2024
1 parent 4a9be6b commit b5e8308
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 18 additions & 0 deletions packages/jui/src/InputField/Input.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,28 @@ describe("Input", () => {
cy.mount(<Input ref={ref} />);
cy.wrap(ref).its("current").should("be.instanceOf", HTMLDivElement);
});

it("forwards ref to the input element", () => {
const ref = React.createRef<HTMLInputElement>();
cy.mount(<Input inputRef={ref} />);
cy.wrap(ref).its("current").should("be.instanceOf", HTMLInputElement);
});

it("doesn't stop propagation of keyboard events", () => {
const onKeyDown = cy.stub();
const onKeyUp = cy.stub();
const onParentKeyDown = cy.stub();
const onParentKeyUp = cy.stub();
cy.mount(
<div onKeyDown={onParentKeyDown} onKeyUp={onParentKeyUp}>
<Input onKeyDown={onKeyDown} onKeyUp={onKeyUp} />
</div>
);
cy.get("input").focus().type("a");
cy.wrap(onKeyDown).should("be.calledOnce");
cy.wrap(onKeyUp).should("be.calledOnce");
cy.wrap(onParentKeyDown).should("be.calledOnce");
cy.wrap(onParentKeyUp).should("be.calledOnce");
});
});
});
4 changes: 0 additions & 4 deletions packages/jui/src/InputField/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ export const Input = React.forwardRef(function Input(
style,
className,
inputRef: inputRefProp,
onKeyDown,
onKeyUp,
onFocus,
onBlur,
autoFocus,
Expand All @@ -164,8 +162,6 @@ export const Input = React.forwardRef(function Input(
autoFocus,
onFocus,
onBlur,
onKeyDown,
onKeyUp,
} as FocusableOptions,
inputRef
);
Expand Down

0 comments on commit b5e8308

Please sign in to comment.