Skip to content

Implement React refs to allow useScrollTrigger based AppBar elevation #30

Closed
campb303 opened this issue Aug 11, 2020 · 2 comments
Closed
Labels
enhancement Request for a change to existing functionality handoff Issues that will not be fixed by the first webqueue2 team (after 7/16/21)

Comments

@campb303
Copy link
Collaborator

Material UI docs give an example for elevating an AppBar using a scroll trigger and this would be useful behavior to indicate when a user has scrolled past content. This can be achieved by creating a ref to the column content and passing that to a scroll trigger as the target. The scroll trigger can then be used to conditionally apply elevation.

Example:

// File w/ Column
import { useRef } from "react";
...
const colRef = useRef();
...
return(
    // Column
    <Box ref={colRef}>
        { /* pass the ref to the appropriate child */ }
    ...
);
// File w/ AppBar
...
const colIsScrolled = useScrollTrigger({
    "target": colRef,
    "threshold": 0
});
...
return(
    <>
        <AppBar position="sticky"
        elevation={colIsScrolled ? 3 : 0}>
        ...
);
...

At the moment, the ref being passed is becoming null. I'm not sure how to fix this and will fix an elevation level until a better solution can be found.

@campb303 campb303 added enhancement Request for a change to existing functionality frontend labels Aug 11, 2020
@campb303 campb303 added this to the v1 milestone Sep 14, 2020
@campb303
Copy link
Collaborator Author

The next step for this is to better understand React refs. ReactJS Tutorial: Refs on YouTube might be useful.

@campb303
Copy link
Collaborator Author

campb303 commented Feb 5, 2021

This is a nice to have but the effort to implement outweighs the benefit. Closing.

@campb303 campb303 closed this as completed Feb 5, 2021
@campb303 campb303 added the handoff Issues that will not be fixed by the first webqueue2 team (after 7/16/21) label Feb 5, 2021
Sign in to join this conversation on GitHub.
Labels
enhancement Request for a change to existing functionality handoff Issues that will not be fixed by the first webqueue2 team (after 7/16/21)
Projects
None yet
Development

No branches or pull requests

1 participant