Update scroll area#645
Merged
AnnMarieW merged 10 commits intosnehilvj:masterfrom Sep 15, 2025
Merged
Conversation
Comment on lines
+9
to
+12
| /** The vertical position as a percentage (0-100).*/ | ||
| top?: number; | ||
| /** The horizontal position as a percentage (0-100). */ | ||
| left?: number; |
Collaborator
There was a problem hiding this comment.
Feels a little funny to me that these numbers are percentages when this interface otherwise LOOKS identical to the underlying scrollTo API that takes pixels. Would it make sense to allow both numbers (treated as pixels) and strings like "100%"?
Collaborator
Author
There was a problem hiding this comment.
oh, yes, that would be much better! Thanks, I'll add that.
Collaborator
Author
|
Here's a sample app to try the scroll to px (number) or to percentage (string) import dash_mantine_components as dmc
from dash import Dash, Input, Output
app = Dash()
component = dmc.ScrollArea(
h=250,
w=350,
id="scrollArea",
children=[
dmc.Paper(
w=600,
children=[
dmc.Title(f"Section {i}", order=3, mt="lg", id=f"section-{i}"),
dmc.Text("This is a sentence. " * 10)
]
)
for i in range(10)
]
)
# Use this to try number of px
controls = dmc.Group([
dmc.NumberInput(label="X position in px", value=0, id="x-position"),
dmc.NumberInput(label="Y position in px", value=0, id="y-position"),
])
# Use this to try percentages
# controls = dmc.Group([
# dmc.Select(label="X position as percentage (string)", id="x-position", data=[f"{i}%" for i in range(0,101, 25)], value="0%"),
# dmc.Select(label="Y position as percentage (string)", id="y-position", data=[f"{i}%" for i in range(0,101, 25)], value="0%"),
# ])
app.layout = dmc.MantineProvider([
controls,
component
])
@app.callback(
Output("scrollArea", "scrollTo"),
Input("x-position", "value"),
Input("y-position", "value"),
)
def scroll_to(x,y):
return {"top": x, "left": y}
if __name__ == "__main__":
app.run(debug=True)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #644
ScrollAreaAutosizecomponentscrollToprop toScrollAreaNew
scrollTooptions:Update - in an earlier version I tried to include an option to scroll to element. However it scrolled the entire page, rather than just the scrollArea, so I removed the feature.
PR for docs (includes examples for both
ScrollAreaAutosizecomponent andscrollToprop) : snehilvj/dmc-docs#243