Skip to content

Commit

Permalink
Select link text input when focused
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Nov 15, 2016
1 parent 2dc95e1 commit f0af4b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion web/client/components/share/ShareLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const ShareLink = React.createClass({
<h4>
<Message msgId="share.directLinkTitle"/>
</h4>
<Input ref="copytext" type="text" value={this.props.shareUrl} addonAfter={copyTo} readOnly/>
<Input onFocus={ev => ev.target.select()} ref="copytext" type="text" value={this.props.shareUrl} addonAfter={copyTo} readOnly/>
</div>
);
}
Expand Down
11 changes: 11 additions & 0 deletions web/client/components/share/__tests__/ShareLink-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ describe("The ShareLink component", () => {
const inputDirectLink = ReactDOM.findDOMNode(ReactTestUtils.scryRenderedDOMComponentsWithTag(cmpShareLink, "input")[0]);
expect(inputDirectLink).toExist();
expect(inputDirectLink.value).toEqual(url);
});

it('should be selected when clicked', () => {
const cmpShareLink = ReactDOM.render(<ShareLink shareUrl={url}/>, document.getElementById("container"));
expect(cmpShareLink).toExist();

const inputDirectLink = ReactDOM.findDOMNode(ReactTestUtils.scryRenderedDOMComponentsWithTag(cmpShareLink, "input")[0]);
expect(inputDirectLink).toExist();

ReactTestUtils.Simulate.focus(inputDirectLink);
let selection = inputDirectLink.value.substring(inputDirectLink.selectionStart, inputDirectLink.selectionEnd);
expect(selection).toEqual(url);
});


Expand Down

0 comments on commit f0af4b4

Please sign in to comment.