瀏覽代碼

Scroll into search bar when focus (#12032)

master^2
Jeong Arm 4 年之前
committed by Eugen Rochko
父節點
當前提交
66fda37fd0
共有 1 個檔案被更改,包括 13 行新增0 行删除
  1. +13
    -0
      app/javascript/mastodon/features/compose/components/search.js

+ 13
- 0
app/javascript/mastodon/features/compose/components/search.js 查看文件

@@ -60,12 +60,17 @@ class Search extends React.PureComponent {
onShow: PropTypes.func.isRequired, onShow: PropTypes.func.isRequired,
openInRoute: PropTypes.bool, openInRoute: PropTypes.bool,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
singleColumn: PropTypes.bool,
}; };


state = { state = {
expanded: false, expanded: false,
}; };


setRef = c => {
this.searchForm = c;
}

handleChange = (e) => { handleChange = (e) => {
this.props.onChange(e.target.value); this.props.onChange(e.target.value);
} }
@@ -95,6 +100,13 @@ class Search extends React.PureComponent {
handleFocus = () => { handleFocus = () => {
this.setState({ expanded: true }); this.setState({ expanded: true });
this.props.onShow(); this.props.onShow();

if (this.searchForm && !this.props.singleColumn) {
const { left, right } = this.searchForm.getBoundingClientRect();
if (left < 0 || right > (window.innerWidth || document.documentElement.clientWidth)) {
this.searchForm.scrollIntoView();
}
}
} }


handleBlur = () => { handleBlur = () => {
@@ -111,6 +123,7 @@ class Search extends React.PureComponent {
<label> <label>
<span style={{ display: 'none' }}>{intl.formatMessage(messages.placeholder)}</span> <span style={{ display: 'none' }}>{intl.formatMessage(messages.placeholder)}</span>
<input <input
ref={this.setRef}
className='search__input' className='search__input'
type='text' type='text'
placeholder={intl.formatMessage(messages.placeholder)} placeholder={intl.formatMessage(messages.placeholder)}


Loading…
取消
儲存