-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60c788a
commit a10f247
Showing
14 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Commands | ||
|
||
Commands are actions that you typically call within an event handler. | ||
|
||
## Navigate | ||
|
||
To navigate to another page, you can use `me.navigate`. This is particularly useful for navigating across a [multi-page](./pages.md) app. | ||
|
||
### Example | ||
|
||
```py | ||
|
||
me.navigate('/path/to/navigate') | ||
|
||
``` | ||
|
||
### API | ||
|
||
::: mesop.commands.navigate.navigate | ||
|
||
## Scroll into view | ||
|
||
If you want to scroll a component into the viewport, you can use `me.scroll_into_view` which scrolls the component with the specified key into the viewport. | ||
|
||
### Example | ||
|
||
```python | ||
--8<-- "mesop/examples/scroll_into_view.py" | ||
``` | ||
|
||
### API | ||
|
||
::: mesop.commands.scroll_into_view.scroll_into_view |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from mesop.runtime import runtime | ||
|
||
|
||
def scroll_into_view(key: str) -> None: | ||
""" | ||
Scrolls so the component specified by the key is in the viewport. | ||
Args: | ||
key: The unique identifier of the component to scroll to. | ||
This key should be globally unique to prevent unexpected behavior. | ||
If multiple components share the same key, the first component | ||
instance found in the component tree will be scrolled to. | ||
""" | ||
runtime().context().scroll_into_view(key) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import mesop as me | ||
|
||
|
||
@me.page(path="/scroll_into_view") | ||
def app(): | ||
me.button("Scroll to middle line", on_click=scroll_to_middle) | ||
me.button("Scroll to bottom line", on_click=scroll_to_bottom) | ||
for _ in range(100): | ||
me.text("Filler line") | ||
me.text("middle_line", key="middle_line") | ||
for _ in range(100): | ||
me.text("Filler line") | ||
me.text("bottom_line", key="bottom_line") | ||
|
||
|
||
def scroll_to_middle(e: me.ClickEvent): | ||
me.scroll_into_view(key="middle_line") | ||
|
||
|
||
def scroll_to_bottom(e: me.ClickEvent): | ||
me.scroll_into_view(key="bottom_line") |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {test, expect} from '@playwright/test'; | ||
|
||
test('scroll_into_view', async ({page}) => { | ||
await page.goto('/scroll_into_view'); | ||
await page.setViewportSize({width: 200, height: 200}); | ||
|
||
await expect(page.getByText('bottom_line')).not.toBeInViewport(); | ||
|
||
await page.getByRole('button', {name: 'Scroll to bottom line'}).click(); | ||
|
||
await expect(page.getByText('bottom_line')).toBeInViewport(); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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