Mobile Web: Auto-focus cursor in the search box (#5284)

* Mobile Web: Auto-focus cursor in the search box and open keyboard when the search icon is tapped

* fixed issue with safari mobile view

* added isFocus props to search_bar.jsx component

* used 'x' and fixed spacing

* changed 'x' icon and fixed css

* added aria-hidden='true'
Этот коммит содержится в:
Saturnino Abril
2017-03-04 03:20:06 +09:00
коммит произвёл enahum
родитель f37c03a75f
Коммит 74c1fbbcf7
5 изменённых файлов: 53 добавлений и 14 удалений

Просмотреть файл

@@ -765,7 +765,12 @@ export default class ChannelHeader extends React.Component {
<th className='header-list__members'> <th className='header-list__members'>
{popoverListMembers} {popoverListMembers}
</th> </th>
<th className='search-bar__container'><NavbarSearchBox showMentionFlagBtns={false}/></th> <th className='search-bar__container'>
<NavbarSearchBox
showMentionFlagBtns={false}
isFocus={Utils.isMobile()}
/>
</th>
<th> <th>
<div className='dropdown channel-header__links search-btns'> <div className='dropdown channel-header__links search-btns'>
<OverlayTrigger <OverlayTrigger

Просмотреть файл

@@ -54,6 +54,12 @@ export default class SearchBar extends React.Component {
componentDidMount() { componentDidMount() {
SearchStore.addSearchTermChangeListener(this.onListenerChange); SearchStore.addSearchTermChangeListener(this.onListenerChange);
this.mounted = true; this.mounted = true;
if (Utils.isMobile()) {
setTimeout(() => {
document.querySelector('.app__body .sidebar--menu').classList.remove('visible');
});
}
} }
componentWillUnmount() { componentWillUnmount() {
@@ -76,6 +82,12 @@ export default class SearchBar extends React.Component {
handleClose(e) { handleClose(e) {
e.preventDefault(); e.preventDefault();
if (Utils.isMobile()) {
setTimeout(() => {
document.querySelector('.app__body .sidebar--menu').classList.add('visible');
});
}
AppDispatcher.handleServerAction({ AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH, type: ActionTypes.RECEIVED_SEARCH,
results: null results: null
@@ -261,7 +273,7 @@ export default class SearchBar extends React.Component {
); );
} }
let clearClass = 'sidebar__clear-icon'; let clearClass = 'sidebar__search-clear';
if (!this.state.isSearching && this.state.searchTerm && this.state.searchTerm.trim() !== '') { if (!this.state.isSearching && this.state.searchTerm && this.state.searchTerm.trim() !== '') {
clearClass += ' visible'; clearClass += ' visible';
} }
@@ -295,13 +307,19 @@ export default class SearchBar extends React.Component {
listComponent={SearchSuggestionList} listComponent={SearchSuggestionList}
providers={this.suggestionProviders} providers={this.suggestionProviders}
type='search' type='search'
autoFocus={this.props.isFocus}
/> />
<span <div
className={clearClass} className={clearClass}
onClick={this.handleClear} onClick={this.handleClear}
> >
<i className='fa fa-times'/> <span
</span> className='sidebar__search-clear-x'
aria-hidden='true'
>
{'×'}
</span>
</div>
{isSearching} {isSearching}
{this.renderHintPopover(helpClass)} {this.renderHintPopover(helpClass)}
</form> </form>
@@ -314,10 +332,12 @@ export default class SearchBar extends React.Component {
} }
SearchBar.defaultProps = { SearchBar.defaultProps = {
showMentionFlagBtns: true showMentionFlagBtns: true,
isFocus: false
}; };
SearchBar.propTypes = { SearchBar.propTypes = {
showMentionFlagBtns: React.PropTypes.bool, showMentionFlagBtns: React.PropTypes.bool,
isCommentsPage: React.PropTypes.bool isCommentsPage: React.PropTypes.bool,
isFocus: React.PropTypes.bool
}; };

Просмотреть файл

@@ -171,7 +171,7 @@ export default class SearchResults extends React.Component {
var currentId = UserStore.getCurrentId(); var currentId = UserStore.getCurrentId();
var searchForm = null; var searchForm = null;
if (currentId) { if (currentId) {
searchForm = <SearchBox/>; searchForm = <SearchBox isFocus={Utils.isMobile()}/>;
} }
var noResults = (!results || !results.order || !results.order.length); var noResults = (!results || !results.order || !results.order.length);
const searchTerm = this.state.searchTerm; const searchTerm = this.state.searchTerm;

Просмотреть файл

@@ -51,7 +51,7 @@
top: 15px; top: 15px;
} }
.sidebar__clear-icon { .sidebar__search-clear {
@include opacity(.5); @include opacity(.5);
color: $dark-gray; color: $dark-gray;
width: 40px; width: 40px;

Просмотреть файл

@@ -933,7 +933,7 @@
.icon--refresh { .icon--refresh {
@include opacity(.6); @include opacity(.6);
color: $black; color: $black;
right: 33px; right: 30px;
top: 15px; top: 15px;
} }
@@ -955,12 +955,19 @@
@include single-transition(transform, .35s, ease); @include single-transition(transform, .35s, ease);
@include translate3d(290px, 0, 0); @include translate3d(290px, 0, 0);
border: none; border: none;
display: block;
width: 290px; width: 290px;
visibility: hidden;
&.visible {
display: block;
visibility: visible;
}
&.move--left, &.move--left,
&.webrtc--show { &.webrtc--show {
@include translate3d(0, 0, 0); @include translate3d(0, 0, 0);
display: block;
visibility: visible;
} }
} }
@@ -1099,15 +1106,22 @@
display: block; display: block;
} }
.sidebar__clear-icon { .sidebar__search-clear {
display: block; display: block;
top: 6px;
height: 30px;
width: 35px;
margin-right: 18px;
&.visible { &.visible {
visibility: visible; visibility: visible;
} }
} }
.fa-times { .sidebar__search-clear-x {
margin-left: 15px; margin-left: 14px;
font-size: 22px;
font-weight: 700;
opacity: .7;
} }
.sidebar--right__close { .sidebar--right__close {