kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
partial completion of replacing componentWillReceiveProps
rodzic
7e1457bb8d
commit
8a43cb3709
|
@ -153,10 +153,13 @@ export default class AutosuggestInput extends ImmutablePureComponent {
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
static getDerivedStateFromProps(nextProps, state) {
|
||||||
if (nextProps.suggestions !== this.props.suggestions && nextProps.suggestions.size > 0 && this.state.suggestionsHidden && this.state.focused) {
|
if (nextProps.suggestions && nextProps.suggestions.size > 0 && state.suggestionsHidden && state.focused) {
|
||||||
this.setState({ suggestionsHidden: false });
|
return {
|
||||||
|
suggestionsHidden: false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInput = (c) => {
|
setInput = (c) => {
|
||||||
|
|
|
@ -159,10 +159,13 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
|
||||||
this.textarea.focus();
|
this.textarea.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
static getDerivedStateFromProps(nextProps, state) {
|
||||||
if (nextProps.suggestions !== this.props.suggestions && nextProps.suggestions.size > 0 && this.state.suggestionsHidden && this.state.focused) {
|
if (nextProps.suggestions && nextProps.suggestions.size > 0 && state.suggestionsHidden && state.focused) {
|
||||||
this.setState({ suggestionsHidden: false });
|
return {
|
||||||
|
suggestionsHidden: false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTextarea = (c) => {
|
setTextarea = (c) => {
|
||||||
|
|
|
@ -267,15 +267,21 @@ class MediaGallery extends React.PureComponent {
|
||||||
state = {
|
state = {
|
||||||
visible: this.props.visible !== undefined ? this.props.visible : (this.props.displayMedia !== 'hide_all' && !this.props.sensitive || this.props.displayMedia === 'show_all'),
|
visible: this.props.visible !== undefined ? this.props.visible : (this.props.displayMedia !== 'hide_all' && !this.props.sensitive || this.props.displayMedia === 'show_all'),
|
||||||
width: this.props.defaultWidth,
|
width: this.props.defaultWidth,
|
||||||
|
media: this.props.media,
|
||||||
|
displayMedia: this.props.displayMedia,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
static getDerivedStateFromProps(nextProps, state) {
|
||||||
const { displayMedia } = this.props;
|
if (!is(nextProps.media, state.media) && nextProps.visible === undefined) {
|
||||||
if (!is(nextProps.media, this.props.media) && nextProps.visible === undefined) {
|
return {
|
||||||
this.setState({ visible: displayMedia !== 'hide_all' && !nextProps.sensitive || displayMedia === 'show_all' });
|
visible: state.displayMedia !== 'hide_all' && !nextProps.sensitive || state.displayMedia === 'show_all',
|
||||||
} else if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {
|
};
|
||||||
this.setState({ visible: nextProps.visible });
|
} else if (!is(nextProps.visible, state.visible) && nextProps.visible !== undefined) {
|
||||||
|
return {
|
||||||
|
visible: nextProps.visible,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleOpen = () => {
|
handleOpen = () => {
|
||||||
|
|
|
@ -78,21 +78,18 @@ class ModalRoot extends React.PureComponent {
|
||||||
window.addEventListener('keyup', this.handleKeyUp, false);
|
window.addEventListener('keyup', this.handleKeyUp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentDidUpdate(nextProps, prevProps) {
|
||||||
if (!!nextProps.children && !this.props.children) {
|
if (!!nextProps.children && !this.props.children) {
|
||||||
this.activeElement = document.activeElement;
|
this.activeElement = document.activeElement;
|
||||||
|
|
||||||
this.getSiblings().forEach(sibling => sibling.setAttribute('inert', true));
|
this.getSiblings().forEach(sibling => sibling.setAttribute('inert', true));
|
||||||
} else if (!nextProps.children) {
|
} else if (!nextProps.children) {
|
||||||
this.setState({ revealed: false });
|
this.setState({ revealed: false });
|
||||||
}
|
}
|
||||||
if (!nextProps.children && !!this.props.children) {
|
if (!nextProps.children && !!this.props.children) {
|
||||||
|
this.activeElement = document.activeElement;
|
||||||
this.activeElement.focus();
|
this.activeElement.focus();
|
||||||
this.activeElement = null;
|
this.activeElement = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
|
||||||
if (!this.props.children && !!prevProps.children) {
|
if (!this.props.children && !!prevProps.children) {
|
||||||
this.getSiblings().forEach(sibling => sibling.removeAttribute('inert'));
|
this.getSiblings().forEach(sibling => sibling.removeAttribute('inert'));
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue