Update modal demo to focus input on open. (#147)

This commit is contained in:
Jason Lee 2024-08-15 09:45:58 +08:00 committed by GitHub
parent a36e3e09d5
commit 6d86e64846
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View file

@ -254,6 +254,8 @@ impl ModalStory {
let overlay = self.modal_overlay;
cx.open_drawer(move |this, cx| {
input.focus_handle(cx).focus(cx);
this.margin_top(px(33.))
.placement(placement)
.overlay(overlay)
@ -305,6 +307,8 @@ impl ModalStory {
let view = cx.view().clone();
cx.open_modal(move |modal, cx| {
input1.focus_handle(cx).focus(cx);
modal
.title("Form Modal")
.overlay(overlay)

View file

@ -299,6 +299,7 @@ impl TextInput {
self.disabled
}
/// Focus the input field.
pub fn focus(&self, cx: &mut ViewContext<Self>) {
self.focus_handle.focus(cx);
}