Desktop: Fixes #2615: Fix issue with disappearing button labels in toolbar (#2619)

* Fix undefined showButtonLabels

* Add showButtonLabels to the state; Removed conditional statement checking if state is undefined
pull/2623/head
Anjula Karunarathne 2020-03-01 16:42:22 +05:30 committed by GitHub
parent 55847fa22f
commit a28b790256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 8 deletions

View File

@ -10,6 +10,7 @@ class HeaderComponent extends React.Component {
this.state = {
searchQuery: '',
showSearchUsageLink: false,
showButtonLabels: true,
};
this.scheduleSearchChangeEventIid_ = null;
@ -83,17 +84,14 @@ class HeaderComponent extends React.Component {
}
if (this.props.zoomFactor !== prevProps.zoomFactor || this.props.size !== prevProps.size) {
const mediaQuery = window.matchMedia(`(max-width: ${550 * this.props.zoomFactor}px)`);
const showButtonLabels = !mediaQuery.matches;
if (this.state.showButtonLabels !== showButtonLabels) {
this.setState({
showButtonLabels: !mediaQuery.matches,
});
}
this.determineButtonLabelState();
}
}
componentDidMount() {
this.determineButtonLabelState();
}
componentWillUnmount() {
if (this.hideSearchUsageLinkIID_) {
clearTimeout(this.hideSearchUsageLinkIID_);
@ -101,6 +99,17 @@ class HeaderComponent extends React.Component {
}
}
determineButtonLabelState() {
const mediaQuery = window.matchMedia(`(max-width: ${550 * this.props.zoomFactor}px)`);
const showButtonLabels = !mediaQuery.matches;
if (this.state.showButtonLabels !== showButtonLabels) {
this.setState({
showButtonLabels: !mediaQuery.matches,
});
}
}
async doCommand(command) {
if (!command) return;