-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hotkey shortcuts for text areas (#922)
Also updates fancy_chat and textarea demos to show usage of shortcuts
- Loading branch information
1 parent
a7c7a77
commit a0585a3
Showing
11 changed files
with
358 additions
and
5 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import input_app as input_app | ||
from . import input_blur_app as input_blur_app | ||
from . import textarea_shortcut_app as textarea_shortcut_app |
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,58 @@ | ||
import mesop as me | ||
|
||
|
||
@me.stateclass | ||
class State: | ||
input: str = "" | ||
output: str = "" | ||
shortcut: str = "" | ||
|
||
|
||
def on_newline(e: me.TextareaShortcutEvent): | ||
state = me.state(State) | ||
state.input = e.value + "\n" | ||
|
||
|
||
def on_submit(e: me.TextareaShortcutEvent): | ||
state = me.state(State) | ||
state.input = e.value | ||
state.output = e.value | ||
|
||
|
||
def on_shortcut(e: me.TextareaShortcutEvent): | ||
state = me.state(State) | ||
state.shortcut = str(e.shortcut) | ||
|
||
|
||
@me.page(path="/components/input/e2e/textarea_shortcut_app") | ||
def app(): | ||
s = me.state(State) | ||
with me.box(style=me.Style(margin=me.Margin.all(15))): | ||
me.textarea( | ||
label="Textarea", | ||
value=s.input, | ||
shortcuts={ | ||
me.Shortcut(key="enter"): on_submit, | ||
me.Shortcut(shift=True, key="ENTER"): on_newline, | ||
me.Shortcut(ctrl=True, alt=True, key="Enter"): on_shortcut, | ||
me.Shortcut(meta=True, key="S"): on_shortcut, | ||
me.Shortcut(key="escape"): on_shortcut, | ||
}, | ||
) | ||
|
||
me.native_textarea( | ||
placeholder="Native textarea", | ||
value=s.input, | ||
autosize=True, | ||
min_rows=5, | ||
shortcuts={ | ||
me.Shortcut(key="enter"): on_submit, | ||
me.Shortcut(shift=True, key="ENTER"): on_newline, | ||
me.Shortcut(ctrl=True, alt=True, key="Enter"): on_shortcut, | ||
me.Shortcut(meta=True, key="S"): on_shortcut, | ||
me.Shortcut(key="escape"): on_shortcut, | ||
}, | ||
) | ||
|
||
me.text(text="Submitted: " + s.output) | ||
me.text(text="Shortcut: " + s.shortcut) |
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
Oops, something went wrong.