Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #14 from outline/jori/escape-search
Browse files Browse the repository at this point in the history
Fixes to link search
  • Loading branch information
tommoor committed Jul 13, 2018
2 parents 611295d + e10273e commit 5421cba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/components/Toolbar/LinkSearchResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const ListItem = styled.a`
height: 28px;
padding: 6px 8px 6px 0;
color: ${props => props.theme.white};
font-family: ${props => props.theme.fontFamily};
font-size: 15px;
text-decoration: none;
overflow: hidden;
white-space: nowrap;
Expand Down
25 changes: 20 additions & 5 deletions src/components/Toolbar/LinkToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ export default class LinkToolbar extends React.Component<Props, State> {
this.save(url);
};

cancel = () => {
this.save(this.originalValue);
};

onKeyDown = (ev: SyntheticKeyboardEvent<*>) => {
switch (ev.which) {
case 13: // enter
switch (ev.key) {
case "Enter":
ev.preventDefault();
if (!(ev.target instanceof HTMLInputElement)) return;
return this.save(ev.target.value);
case 27: // escape
return this.save(this.originalValue);
case 40: // down
case "Escape":
ev.preventDefault();
ev.stopPropagation();
return this.cancel();
case "ArrowDown":
ev.preventDefault();
if (this.firstDocument) {
const element = findDOMNode(this.firstDocument);
Expand All @@ -138,6 +144,14 @@ export default class LinkToolbar extends React.Component<Props, State> {
this.setState({ results: [] });
};

onResultKeyDown = (ev: SyntheticKeyboardEvent<*>) => {
if (ev.key === "Escape") {
ev.preventDefault();
ev.stopPropagation();
this.cancel();
}
};
removeLink = () => {
this.save("");
};
Expand Down Expand Up @@ -202,6 +216,7 @@ export default class LinkToolbar extends React.Component<Props, State> {
title={result.title}
key={result.url}
onClick={ev => this.selectSearchResult(ev, result.url)}
onKeyDown={this.onResultKeyDown}
/>
))}
</ArrowKeyNavigation>
Expand Down

0 comments on commit 5421cba

Please sign in to comment.