fix(feedback): Scroll to the top when opening feedback dialog

This commit is contained in:
Vlad Piersec
2021-09-15 11:13:05 +03:00
committed by vp8x8
parent 07da5940a5
commit 380ef3da0b
2 changed files with 27 additions and 11 deletions

View File

@@ -28,8 +28,7 @@ const OK_BUTTON_ID = 'modal-dialog-ok-button';
*
* @static
*/
type Props = {
...DialogProps,
type Props = DialogProps & {
/**
* Custom dialog header that replaces the standard heading.
@@ -77,6 +76,11 @@ type Props = {
*/
onDecline?: Function,
/**
* Callback invoked when setting the ref of the Dialog.
*/
onDialogRef?: Function,
/**
* Disables rendering of the submit button.
*/
@@ -127,7 +131,7 @@ class StatelessDialog extends Component<Props> {
this._onKeyPress = this._onKeyPress.bind(this);
this._onSubmit = this._onSubmit.bind(this);
this._renderFooter = this._renderFooter.bind(this);
this._setDialogElement = this._setDialogElement.bind(this);
this._onDialogRef = this._onDialogRef.bind(this);
}
/**
@@ -166,7 +170,7 @@ class StatelessDialog extends Component<Props> {
width = { width || 'medium' }>
<div
onKeyPress = { this._onKeyPress }
ref = { this._setDialogElement }>
ref = { this._onDialogRef }>
<form
className = 'modal-dialog-form'
id = 'modal-dialog-form'
@@ -319,19 +323,18 @@ class StatelessDialog extends Component<Props> {
);
}
_setDialogElement: (?HTMLElement) => void;
_onDialogRef: (?Element) => void;
/**
* Sets the instance variable for the div containing the component's dialog
* element so it can be accessed directly.
* Callback invoked when setting the ref of the dialog's child passing the Modal ref.
* It is done this way because we cannot directly access the ref of the Modal component.
*
* @param {HTMLElement} element - The DOM element for the component's
* dialog.
* @param {HTMLElement} element - The DOM element for the dialog.
* @private
* @returns {void}
*/
_setDialogElement(element: ?HTMLElement) {
this._dialogElement = element;
_onDialogRef(element: ?Element) {
this.props.onDialogRef && this.props.onDialogRef(element && element.parentNode);
}
_onKeyPress: (Object) => void;