button: Bind element ID after button is created (#1325)
- Fix the selected-state error in the popup menu.
This commit is contained in:
parent
1358b2906e
commit
9754cab4d7
1 changed files with 9 additions and 6 deletions
|
|
@ -7,8 +7,8 @@ use crate::{
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, px, relative, Action, AnyElement, App, ClickEvent, Corners,
|
div, prelude::FluentBuilder as _, px, relative, Action, AnyElement, App, ClickEvent, Corners,
|
||||||
Div, Edges, ElementId, Hsla, InteractiveElement, Interactivity, IntoElement, ParentElement,
|
Div, Edges, ElementId, Hsla, InteractiveElement, Interactivity, IntoElement, ParentElement,
|
||||||
Pixels, RenderOnce, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled,
|
Pixels, RenderOnce, SharedString, Stateful, StatefulInteractiveElement as _, StyleRefinement,
|
||||||
Window,
|
Styled, Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default, Clone, Copy)]
|
#[derive(Default, Clone, Copy)]
|
||||||
|
|
@ -182,7 +182,7 @@ impl ButtonVariant {
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Button {
|
pub struct Button {
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
base: Div,
|
base: Stateful<Div>,
|
||||||
style: StyleRefinement,
|
style: StyleRefinement,
|
||||||
icon: Option<Icon>,
|
icon: Option<Icon>,
|
||||||
label: Option<SharedString>,
|
label: Option<SharedString>,
|
||||||
|
|
@ -217,9 +217,13 @@ impl From<Button> for AnyElement {
|
||||||
|
|
||||||
impl Button {
|
impl Button {
|
||||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||||
|
let id = id.into();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id: id.into(),
|
id: id.clone(),
|
||||||
base: div().flex_shrink_0(),
|
// ID must be set after div is created;
|
||||||
|
// `popup_menu` uses this id to create the popup menu.
|
||||||
|
base: div().flex_shrink_0().id(id),
|
||||||
style: StyleRefinement::default(),
|
style: StyleRefinement::default(),
|
||||||
icon: None,
|
icon: None,
|
||||||
label: None,
|
label: None,
|
||||||
|
|
@ -415,7 +419,6 @@ impl RenderOnce for Button {
|
||||||
let is_focused = focus_handle.is_focused(window);
|
let is_focused = focus_handle.is_focused(window);
|
||||||
|
|
||||||
self.base
|
self.base
|
||||||
.id(self.id.clone())
|
|
||||||
.when(!self.disabled, |this| {
|
.when(!self.disabled, |this| {
|
||||||
this.track_focus(
|
this.track_focus(
|
||||||
&focus_handle
|
&focus_handle
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue