Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 92f3177

Browse files
2007heavenjasonLaster
authored andcommitted
Fix [QuickOpenModal] initial scroll (#5311)
* Fix scrolling to [QuickOpenModal] result item By delaying it to take Modal Transition timeout into account. * Omit timeout if delayed opt is false * [QuickOpenModal] Delay scroll for certain conditions Delay if modal was just enabled or query did not change. * fix prettier error * Fix linting import aliasing exceeding line error
1 parent 3dbf9d3 commit 92f3177

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/components/QuickOpenModal.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,17 @@ export class QuickOpenModal extends Component<Props, State> {
9696
}
9797

9898
componentDidUpdate(prevProps: Props) {
99+
const nowEnabled = !prevProps.enabled && this.props.enabled;
100+
const queryChanged = prevProps.query !== this.props.query;
101+
99102
if (this.refs.resultList && this.refs.resultList.refs) {
100-
scrollList(this.refs.resultList.refs, this.state.selectedIndex);
103+
scrollList(
104+
this.refs.resultList.refs,
105+
this.state.selectedIndex,
106+
nowEnabled || !queryChanged
107+
);
101108
}
102109

103-
const nowEnabled = !prevProps.enabled && this.props.enabled;
104-
const queryChanged = prevProps.query !== this.props.query;
105110
if (nowEnabled || queryChanged) {
106111
this.updateResults(this.props.query);
107112
}

src/components/shared/Modal.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type ModalProps = {
2020
handleClose: () => any
2121
};
2222

23+
export const transitionTimeout = 175;
24+
2325
export class Modal extends React.Component<ModalProps> {
2426
onClick = (e: SyntheticEvent<HTMLElement>) => {
2527
e.stopPropagation();
@@ -59,7 +61,7 @@ export default function Slide({
5961
handleClose
6062
}: SlideProps) {
6163
return (
62-
<Transition in={inProp} timeout={175} appear>
64+
<Transition in={inProp} timeout={transitionTimeout} appear>
6365
{(status: TransitionStatus) => (
6466
<Modal
6567
status={status}

src/utils/result-list.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
44

55
import { isFirefox } from "devtools-config";
6+
import { transitionTimeout } from "../components/shared/Modal";
67

7-
function scrollList(resultList, index) {
8+
function scrollList(resultList, index, delayed = false) {
89
if (!resultList.hasOwnProperty(index)) {
910
return;
1011
}
1112

1213
const resultEl = resultList[index];
1314

14-
if (isFirefox()) {
15-
resultEl.scrollIntoView({ block: "center", behavior: "smooth" });
16-
} else {
17-
chromeScrollList(resultEl, index);
15+
const scroll = () => {
16+
if (isFirefox()) {
17+
resultEl.scrollIntoView({ block: "center", behavior: "smooth" });
18+
} else {
19+
chromeScrollList(resultEl, index);
20+
}
21+
};
22+
23+
if (delayed) {
24+
// Wait for Modal Transition timeout before scrolling to resultEl.
25+
setTimeout(scroll, transitionTimeout + 10);
26+
return;
1827
}
28+
29+
scroll();
1930
}
2031

2132
function chromeScrollList(elem, index) {

0 commit comments

Comments
 (0)