From 1e1a5e37985cb0410243f8cfeee9092621206d04 Mon Sep 17 00:00:00 2001 From: Gal Angel Date: Sat, 25 Jan 2025 13:48:15 +0200 Subject: [PATCH] Adjust scroll behavior logic in Scroll component (#48) --- CONTRIBUTING.md | 2 +- README.md | 21 --------------------- src/components/Scroll/Scroll.provider.tsx | 5 ++++- src/components/Scroll/types.ts | 2 +- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a5c79f4..5a84afe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,7 @@ git clone https://github.com/your-username/react-scroll-magic.git 3. **Create a branch**: -- please use the github project to generate a branch for you, you can then use it to checkout locally manually or use github desktop +- please use the github issues to generate a branch for you, you can then use it to checkout locally manually or use github desktop ## Making Changes diff --git a/README.md b/README.md index 00494e5..5425e44 100644 --- a/README.md +++ b/README.md @@ -59,27 +59,6 @@ The Scroll Component accepts the following props: | `stickTo` | `top`\|`bottom`\|`all` | how headers should stick | | `scrollBehavior` | `scrollBehavior CSS property` | how the scrolling should behave when clicking a header | -## Wishlist - -### Scroll - -- [ ] Virtualized scrolling -- [ ] Snap scrolling -- [ ] Horizontal scrolling support -- [ ] Scroll shadow -- [ ] Maximum number of sticky items -- [ ] Stacking headers -- [ ] Collapse header items -- [ ] Scroll to item scroll via code - -### Repo management - -- [ ] Better tests -- [ ] Better looking doc site with more (interactive) examples -- [ ] Changelog file -- [ ] Enforce code style using eslint -- [ ] Ensure support for popular frameworks or libraries - ## License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. diff --git a/src/components/Scroll/Scroll.provider.tsx b/src/components/Scroll/Scroll.provider.tsx index 2cc1fdf..edc8b1d 100644 --- a/src/components/Scroll/Scroll.provider.tsx +++ b/src/components/Scroll/Scroll.provider.tsx @@ -72,7 +72,10 @@ export const HeadersProvider: React.FC = ({ parseFloat(nextItemStyles.borderTopWidth) + parseFloat(nextItemStyles.borderBottomWidth); - const top = Math.ceil(nextItem.offsetTop - headersOffset - headerHeight + nextItemStyleOffset); + const top = + stickTo === 'bottom' + ? Math.ceil(nextItem.offsetTop - headerHeight) + : Math.ceil(nextItem.offsetTop - headersOffset - headerHeight + nextItemStyleOffset); listRef.scrollTo({ top, behavior: scrollBehavior }); } diff --git a/src/components/Scroll/types.ts b/src/components/Scroll/types.ts index 4313366..9d1fb19 100644 --- a/src/components/Scroll/types.ts +++ b/src/components/Scroll/types.ts @@ -1,6 +1,6 @@ export type StickTo = 'top' | 'bottom' | 'all'; -export type HeaderBehavior = 'stick' | 'push' | 'stack' | 'none'; +export type HeaderBehavior = 'stick' | 'push' | 'none'; export type Collapse = { open: () => void;