Unverified Commit 507ab36d authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[fragment-scroll] Cleanup scroll and focus restoration in layout router (#83110)

Just removing some unnecessary runtime checks and typecasts to make future diffs smaller.
parent d41c50b8
...@@ -127,7 +127,7 @@ interface ScrollAndFocusHandlerProps { ...@@ -127,7 +127,7 @@ interface ScrollAndFocusHandlerProps {
} }
class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerProps> { class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerProps> {
handlePotentialScroll = () => { handlePotentialScroll = () => {
// Handle scroll and focus, it's only applied once in the first useEffect that triggers that changed. // Handle scroll and focus, it's only applied once.
const { focusAndScrollRef, segmentPath } = this.props const { focusAndScrollRef, segmentPath } = this.props
if (focusAndScrollRef.apply) { if (focusAndScrollRef.apply) {
...@@ -192,7 +192,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr ...@@ -192,7 +192,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
() => { () => {
// In case of hash scroll, we only need to scroll the element into view // In case of hash scroll, we only need to scroll the element into view
if (hashFragment) { if (hashFragment) {
;(domNode as HTMLElement).scrollIntoView() domNode.scrollIntoView()
return return
} }
...@@ -202,7 +202,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr ...@@ -202,7 +202,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
const viewportHeight = htmlElement.clientHeight const viewportHeight = htmlElement.clientHeight
// If the element's top edge is already in the viewport, exit early. // If the element's top edge is already in the viewport, exit early.
if (topOfElementInViewport(domNode as HTMLElement, viewportHeight)) { if (topOfElementInViewport(domNode, viewportHeight)) {
return return
} }
...@@ -213,9 +213,9 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr ...@@ -213,9 +213,9 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
htmlElement.scrollTop = 0 htmlElement.scrollTop = 0
// Scroll to domNode if domNode is not in viewport when scrolled to top of document // Scroll to domNode if domNode is not in viewport when scrolled to top of document
if (!topOfElementInViewport(domNode as HTMLElement, viewportHeight)) { if (!topOfElementInViewport(domNode, viewportHeight)) {
// Scroll into view doesn't scroll horizontally by default when not needed // Scroll into view doesn't scroll horizontally by default when not needed
;(domNode as HTMLElement).scrollIntoView() domNode.scrollIntoView()
} }
}, },
{ {
...@@ -238,10 +238,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr ...@@ -238,10 +238,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
} }
componentDidUpdate() { componentDidUpdate() {
// Because this property is overwritten in handlePotentialScroll it's fine to always run it when true as it'll be set to false for subsequent renders. this.handlePotentialScroll()
if (this.props.focusAndScrollRef.apply) {
this.handlePotentialScroll()
}
} }
render() { render() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment