diff --git a/src/elements/Input/Input.js b/src/elements/Input/Input.js
index a267ed2000..5f35f2e736 100644
--- a/src/elements/Input/Input.js
+++ b/src/elements/Input/Input.js
@@ -117,6 +117,8 @@ class Input extends Component {
focus = () => this.inputRef.focus()
+ select = () => this.inputRef.select()
+
handleChange = (e) => {
const value = _.get(e, 'target.value')
diff --git a/test/specs/elements/Input/Input-test.js b/test/specs/elements/Input/Input-test.js
index 5eb0030080..216654f38d 100644
--- a/test/specs/elements/Input/Input-test.js
+++ b/test/specs/elements/Input/Input-test.js
@@ -71,9 +71,14 @@ describe('Input', () => {
common.propKeyAndValueToClassName(Input, 'actionPosition', ['left'], { className: 'action' })
common.propKeyAndValueToClassName(Input, 'iconPosition', ['left'], { className: 'icon' })
- common.propKeyAndValueToClassName(Input, 'labelPosition', ['left', 'right', 'left corner', 'right corner'], {
- className: 'labeled',
- })
+ common.propKeyAndValueToClassName(
+ Input,
+ 'labelPosition',
+ ['left', 'right', 'left corner', 'right corner'],
+ {
+ className: 'labeled',
+ },
+ )
common.propKeyOnlyToClassName(Input, 'action')
common.propKeyOnlyToClassName(Input, 'disabled')
@@ -113,13 +118,9 @@ describe('Input', () => {
const wrapper = shallow()
// account for overloading the onChange prop
- const expectedValue = propName === 'onChange'
- ? wrapper.instance().handleChange
- : propValue
+ const expectedValue = propName === 'onChange' ? wrapper.instance().handleChange : propValue
- wrapper
- .find('input')
- .should.have.prop(propName, expectedValue)
+ wrapper.find('input').should.have.prop(propName, expectedValue)
})
it(`passes \`${propName}\` to the when using children`, () => {
@@ -131,13 +132,9 @@ describe('Input', () => {
)
// account for overloading the onChange prop
- const expectedValue = propName === 'onChange'
- ? wrapper.instance().handleChange
- : propValue
+ const expectedValue = propName === 'onChange' ? wrapper.instance().handleChange : propValue
- wrapper
- .find('input')
- .should.have.prop(propName, expectedValue)
+ wrapper.find('input').should.have.prop(propName, expectedValue)
})
})
})
@@ -158,6 +155,25 @@ describe('Input', () => {
})
})
+ describe('select', () => {
+ it('can be set via a ref', () => {
+ const mountNode = document.createElement('div')
+ document.body.appendChild(mountNode)
+
+ const value = 'expect this text to be selected'
+ const wrapper = mount(, { attachTo: mountNode })
+ wrapper.instance().select()
+
+ window
+ .getSelection()
+ .toString()
+ .should.equal(value)
+
+ wrapper.detach()
+ document.body.removeChild(mountNode)
+ })
+ })
+
describe('loading', () => {
it("don't add icon if it's defined", () => {
shallow()
@@ -210,7 +226,12 @@ describe('Input', () => {
const mountNode = document.createElement('div')
document.body.appendChild(mountNode)
- const wrapper = mount(, { attachTo: mountNode })
+ const wrapper = mount(
+
+
+ ,
+ { attachTo: mountNode },
+ )
const input = document.querySelector('.ui.input input')
ref.should.have.been.calledOnce()