mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-02-15 15:13:48 -05:00
[Glitch] Scroll into search bar when focus
Port 66fda37fd04de989d12f3f4c565ba5bfc6ee189d to glitch-soc Signed-off-by: Thibaut Girka <thib@sitedethib.com>
This commit is contained in:
parent
79388a52aa
commit
c274774d06
@ -73,12 +73,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) => {
|
||||||
const { onChange } = this.props;
|
const { onChange } = this.props;
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
@ -103,10 +108,14 @@ class Search extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleFocus = () => {
|
handleFocus = () => {
|
||||||
const { onShow } = this.props;
|
|
||||||
this.setState({ expanded: true });
|
this.setState({ expanded: true });
|
||||||
if (onShow) {
|
this.props.onShow();
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +144,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…
x
Reference in New Issue
Block a user