Skip to content

Commit 38ffaf6

Browse files
committed
Update URL with search query, select text
1 parent 86d78d7 commit 38ffaf6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/search/components/SearchForm.js

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export class SearchFormBase extends React.Component {
1919
router: PropTypes.object,
2020
}
2121

22+
componentDidMount() {
23+
this.refs.query.select();
24+
}
25+
2226
goToSearch(query) {
2327
const { pathname } = this.props;
2428
this.context.router.push(`${pathname}?q=${query}`);

src/search/components/SearchPage.js

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SearchResults from './SearchResults';
99
export default class SearchPage extends React.Component {
1010
static propTypes = {
1111
count: PropTypes.number,
12+
location: PropTypes.object.isRequired,
1213
loading: PropTypes.bool.isRequired,
1314
page: PropTypes.number,
1415
results: PropTypes.arrayOf(PropTypes.shape({
@@ -18,6 +19,22 @@ export default class SearchPage extends React.Component {
1819
query: PropTypes.string,
1920
}
2021

22+
static contextTypes = {
23+
router: PropTypes.object.isRequired,
24+
}
25+
26+
componentDidMount() {
27+
const { location, query } = this.props;
28+
const { router } = this.context;
29+
const url = {
30+
...location,
31+
query: { ...location.query, q: query },
32+
};
33+
if (query && !router.isActive(url)) {
34+
router.replace(url);
35+
}
36+
}
37+
2138
render() {
2239
const { count, loading, page, query, results } = this.props;
2340
const pathname = '/search/';

0 commit comments

Comments
 (0)