Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Scrollbar): add support for programmable scrolling with scrollTop, scrollLeft, and scrollViewRef props #809

Merged
merged 4 commits into from
Nov 16, 2023

Conversation

cheton
Copy link
Member

@cheton cheton commented Nov 16, 2023

Add support for programmable scrolling with scrollTop, scrollLeft, and scrollViewRef props.

Examples

Using scrollTop prop

import { Box, Button, Scrollbar } from "@tonic-ui/react";
import { useToggle } from "@tonic-ui/react-hooks";
import React, { useRef } from "react";
import Lorem from "@/components/Lorem";

const App = () => {
  const lastScrollTopRef = useRef();
  const [on, toggle] = useToggle(true);

  return (
    <>
      <Box mb="4x">
        <Button onClick={toggle}>Toggle</Button>
      </Box>
      {on && (
        <Scrollbar
          height={200}
          onUpdate={(values) => {
            lastScrollTopRef.current = values.scrollTop;
          }}
          scrollTop={lastScrollTopRef.current}
        >
          <Lorem count={10} />
        </Scrollbar>
      )}
    </>
  );
};

export default App;

Using scrollViewRef prop

import { Box, Scrollbar } from "@tonic-ui/react";
import React, { useRef } from "react";

const App = () => {
  const scrollViewRef = useRef();

  return (
    <Scrollbar height={200} scrollViewRef={scrollViewRef}>
      <Box height={400}>Scroll content</Box>
    </Scrollbar>
  );
};

export default App;

Copy link

codesandbox bot commented Nov 16, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@cheton cheton linked an issue Nov 16, 2023 that may be closed by this pull request
Copy link

codesandbox-ci bot commented Nov 16, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1ae4864:

Sandbox Source
zealous-flower-q2flqm PR

@trendmicro-frontend-bot
Copy link
Contributor

trendmicro-frontend-bot commented Nov 16, 2023

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (29e733a) 71.40% compared to head (1ae4864) 71.34%.

Files Patch % Lines
packages/react/src/scrollbar/Scrollbar.js 83.33% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #809      +/-   ##
==========================================
- Coverage   71.40%   71.34%   -0.06%     
==========================================
  Files         374      374              
  Lines        6267     6272       +5     
==========================================
  Hits         4475     4475              
- Misses       1792     1797       +5     
Flag Coverage Δ
react 73.05% <83.33%> (-0.08%) ⬇️
react-hooks 87.59% <ø> (ø)
react-lab 14.04% <ø> (ø)
styled-system 91.73% <ø> (ø)
theme 100.00% <ø> (ø)
utils 70.28% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cheton cheton changed the title feat(Scrollbar): enable scrolling to specific positions using scrollTop or scrollLeft props feat(Scrollbar): support programmable scrolling using scrollTop, scrollLeft, and scrollViewRef props Nov 16, 2023
@cheton cheton changed the title feat(Scrollbar): support programmable scrolling using scrollTop, scrollLeft, and scrollViewRef props feat(Scrollbar): add support for programmable scrolling with scrollTop, scrollLeft, and scrollViewRef props Nov 16, 2023
@cheton cheton merged commit e7c5b2d into master Nov 16, 2023
3 of 4 checks passed
@cheton cheton deleted the tonic-ui-807 branch November 16, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Idea: Scrollbar component supports scrolling to position
3 participants