Skip to content

Commit

Permalink
Update URL with search query, select text
Browse files Browse the repository at this point in the history
  • Loading branch information
mstriemer committed Aug 24, 2016
1 parent 86d78d7 commit 38ffaf6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/search/components/SearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class SearchFormBase extends React.Component {
router: PropTypes.object,
}

componentDidMount() {
this.refs.query.select();
}

goToSearch(query) {
const { pathname } = this.props;
this.context.router.push(`${pathname}?q=${query}`);
Expand Down
17 changes: 17 additions & 0 deletions src/search/components/SearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SearchResults from './SearchResults';
export default class SearchPage extends React.Component {
static propTypes = {
count: PropTypes.number,
location: PropTypes.object.isRequired,
loading: PropTypes.bool.isRequired,
page: PropTypes.number,
results: PropTypes.arrayOf(PropTypes.shape({
Expand All @@ -18,6 +19,22 @@ export default class SearchPage extends React.Component {
query: PropTypes.string,
}

static contextTypes = {
router: PropTypes.object.isRequired,
}

componentDidMount() {
const { location, query } = this.props;
const { router } = this.context;
const url = {
...location,
query: { ...location.query, q: query },
};
if (query && !router.isActive(url)) {
router.replace(url);
}
}

render() {
const { count, loading, page, query, results } = this.props;
const pathname = '/search/';
Expand Down

0 comments on commit 38ffaf6

Please sign in to comment.