-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(Input): add handling of input's ref #1581
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,14 +53,14 @@ describe('Input', () => { | |
common.hasUIClassName(Input) | ||
common.rendersChildren(Input) | ||
|
||
common.implementsLabelProp(Input, { | ||
shorthandDefaultProps: { className: 'label' }, | ||
}) | ||
common.implementsButtonProp(Input, { | ||
propKey: 'action', | ||
shorthandDefaultProps: { className: 'button' }, | ||
}) | ||
common.implementsCreateMethod(Input) | ||
common.implementsLabelProp(Input, { | ||
shorthandDefaultProps: { className: 'label' }, | ||
}) | ||
common.implementsHTMLInputProp(Input, { | ||
alwaysPresent: true, | ||
shorthandDefaultProps: { type: 'text' }, | ||
|
@@ -138,6 +138,22 @@ describe('Input', () => { | |
}) | ||
}) | ||
|
||
describe('focus', () => { | ||
it('can be set via a ref', () => { | ||
const mountNode = document.createElement('div') | ||
document.body.appendChild(mountNode) | ||
|
||
const wrapper = mount(<Input />, { attachTo: mountNode }) | ||
wrapper.instance().focus() | ||
|
||
const input = document.querySelector('.ui.input input') | ||
document.activeElement.should.equal(input) | ||
|
||
wrapper.detach() | ||
document.body.removeChild(mountNode) | ||
}) | ||
}) | ||
|
||
describe('onChange', () => { | ||
it('is called with (e, data) on change', () => { | ||
const spy = sandbox.spy() | ||
|
@@ -170,42 +186,39 @@ describe('Input', () => { | |
}) | ||
}) | ||
|
||
describe('ref', () => { | ||
it('maintains ref on child node', () => { | ||
const ref = sandbox.spy() | ||
const wrapper = mount(<Input><input ref={ref} /></Input>) | ||
|
||
// ref.should.have.been.calledOnce() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @levithomason I can't get this test working, can you take a look? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refs are not passed through props. React makes them undefined. We'll have to accept the ref on a different prop name, or, update factories to include refs in the overrides. We should probably use a different prop name, such as, |
||
wrapper.instance().inputRef.tagName.should.equal('INPUT') | ||
}) | ||
}) | ||
|
||
describe('tabIndex', () => { | ||
it('is not set by default', () => { | ||
shallow(<Input />) | ||
.find('input') | ||
.should.not.have.prop('tabIndex') | ||
}) | ||
|
||
it('defaults to -1 when disabled', () => { | ||
shallow(<Input disabled />) | ||
.find('input') | ||
.should.have.prop('tabIndex', -1) | ||
}) | ||
|
||
it('can be set explicitly', () => { | ||
shallow(<Input tabIndex={123} />) | ||
.find('input') | ||
.should.have.prop('tabIndex', 123) | ||
}) | ||
|
||
it('can be set explicitly when disabled', () => { | ||
shallow(<Input tabIndex={123} disabled />) | ||
.find('input') | ||
.should.have.prop('tabIndex', 123) | ||
}) | ||
}) | ||
|
||
describe('focus', () => { | ||
it('can be set via a ref', () => { | ||
const mountNode = document.createElement('div') | ||
document.body.appendChild(mountNode) | ||
|
||
const wrapper = mount(<Input />, { attachTo: mountNode }) | ||
wrapper.instance().focus() | ||
|
||
const input = document.querySelector('.ui.input input') | ||
document.activeElement.should.equal(input) | ||
|
||
wrapper.detach() | ||
document.body.removeChild(mountNode) | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use factory instead of
cloneElement