Skip to content

Commit

Permalink
Adjust scroll behavior logic in Scroll component (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
galangel authored Jan 25, 2025
1 parent edc5422 commit 1e1a5e3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion src/components/Scroll/Scroll.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export const HeadersProvider: React.FC<IHeadersProvider> = ({
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 });
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Scroll/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 1e1a5e3

Please sign in to comment.