Skip to content

Commit

Permalink
[core] chore: remove checks for React.createRef undefined (#5821)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Jan 4, 2023
1 parent 6fc0dfa commit ddecb32
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
20 changes: 9 additions & 11 deletions packages/core/test/buttons/buttonTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,16 @@ function buttonTestSuite(component: React.ComponentClass<any>, tagName: string)
checkClickTriggeredOnKeyUp(done, {}, { which: Keys.SPACE });
});

if (typeof React.createRef !== "undefined") {
it("matches buttonRef with elementRef.current using createRef", done => {
const elementRef = React.createRef<HTMLButtonElement>();
const wrapper = button({ elementRef }, true);
it("matches buttonRef with elementRef.current using createRef", done => {
const elementRef = React.createRef<HTMLButtonElement>();
const wrapper = button({ elementRef }, true);

// wait for the whole lifecycle to run
setTimeout(() => {
assert.equal(elementRef.current, (wrapper.instance() as any).buttonRef);
done();
}, 0);
});
}
// wait for the whole lifecycle to run
setTimeout(() => {
assert.equal(elementRef.current, (wrapper.instance() as any).buttonRef);
done();
}, 0);
});

it("matches buttonRef with elementRef using callback", done => {
let elementRef: HTMLElement | null = null;
Expand Down
20 changes: 9 additions & 11 deletions packages/core/test/forms/textAreaTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,15 @@ describe("<TextArea>", () => {
assert.instanceOf(textAreaNew, HTMLTextAreaElement);
});

if (typeof React.createRef !== "undefined") {
it("accepts object refs created with React.createRef and updates on change", () => {
const textAreaRef = React.createRef<HTMLTextAreaElement>();
const textAreaNewRef = React.createRef<HTMLTextAreaElement>();
it("accepts object refs created with React.createRef and updates on change", () => {
const textAreaRef = React.createRef<HTMLTextAreaElement>();
const textAreaNewRef = React.createRef<HTMLTextAreaElement>();

const textAreawrapper = mount(<TextArea id="textarea" inputRef={textAreaRef} />);
assert.instanceOf(textAreaRef.current, HTMLTextAreaElement);
const textAreawrapper = mount(<TextArea id="textarea" inputRef={textAreaRef} />);
assert.instanceOf(textAreaRef.current, HTMLTextAreaElement);

textAreawrapper.setProps({ inputRef: textAreaNewRef });
assert.isNull(textAreaRef.current);
assert.instanceOf(textAreaNewRef.current, HTMLTextAreaElement);
});
}
textAreawrapper.setProps({ inputRef: textAreaNewRef });
assert.isNull(textAreaRef.current);
assert.instanceOf(textAreaNewRef.current, HTMLTextAreaElement);
});
});
20 changes: 9 additions & 11 deletions packages/core/test/tag/tagTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,14 @@ describe("<Tag>", () => {
assert.deepEqual(handleRemove.args[0][1][DATA_ATTR_FOO], tagProps[DATA_ATTR_FOO]);
});

if (typeof React.createRef !== "undefined") {
it("supports ref objects", done => {
const elementRef = React.createRef<HTMLSpanElement>();
const wrapper = mount(<Tag elementRef={elementRef}>Hello</Tag>);
it("supports ref objects", done => {
const elementRef = React.createRef<HTMLSpanElement>();
const wrapper = mount(<Tag elementRef={elementRef}>Hello</Tag>);

// wait for the whole lifecycle to run
setTimeout(() => {
assert.equal(elementRef.current, wrapper.find(`.${Classes.TAG}`).getDOMNode<HTMLSpanElement>());
done();
}, 0);
});
}
// wait for the whole lifecycle to run
setTimeout(() => {
assert.equal(elementRef.current, wrapper.find(`.${Classes.TAG}`).getDOMNode<HTMLSpanElement>());
done();
}, 0);
});
});

1 comment on commit ddecb32

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[core] chore: remove checks for React.createRef undefined (#5821)

Previews: documentation | landing | table | demo

Please sign in to comment.