Skip to content

Commit 434353c

Browse files
committed
Fix bug with event propagation cancellation
1 parent dbc1432 commit 434353c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

crates/bevy_ui_widgets/src/radio.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bevy_ecs::{
66
entity::Entity,
77
hierarchy::{ChildOf, Children},
88
observer::On,
9-
query::{Has, With, Without},
9+
query::{Has, With},
1010
reflect::ReflectComponent,
1111
system::{Commands, Query},
1212
};
@@ -156,28 +156,28 @@ fn radio_group_on_key_input(
156156
// on `Space` or `Enter` key press.
157157
fn radio_button_on_key_input(
158158
mut ev: On<FocusedInput<KeyboardInput>>,
159-
q_radio_button: Query<Has<Checked>, (With<RadioButton>, Without<InteractionDisabled>)>,
159+
q_radio_button: Query<(Has<InteractionDisabled>, Has<Checked>), With<RadioButton>>,
160160
q_group: Query<(), With<RadioGroup>>,
161161
q_parents: Query<&ChildOf>,
162162
mut commands: Commands,
163163
) {
164-
let Ok(checked) = q_radio_button.get(ev.focused_entity) else {
164+
let Ok((disabled, checked)) = q_radio_button.get(ev.focused_entity) else {
165165
// Not a radio button
166166
return;
167167
};
168168

169-
// Radio button already checked
170-
if checked {
171-
return;
172-
}
173-
174169
let event = &ev.event().input;
175170
if event.state == ButtonState::Pressed
176171
&& !event.repeat
177172
&& (event.key_code == KeyCode::Enter || event.key_code == KeyCode::Space)
178173
{
179174
ev.propagate(false);
180175

176+
// Radio button is disabled or already checked
177+
if disabled || checked {
178+
return;
179+
}
180+
181181
trigger_radio_button_and_radio_group_value_change(
182182
ev.focused_entity,
183183
&q_group,
@@ -190,19 +190,19 @@ fn radio_button_on_key_input(
190190
fn radio_button_on_click(
191191
mut ev: On<Pointer<Click>>,
192192
q_group: Query<(), With<RadioGroup>>,
193-
q_radio: Query<Has<Checked>, (With<RadioButton>, Without<InteractionDisabled>)>,
193+
q_radio: Query<(Has<InteractionDisabled>, Has<Checked>), With<RadioButton>>,
194194
q_parents: Query<&ChildOf>,
195195
mut commands: Commands,
196196
) {
197-
let Ok(checked) = q_radio.get(ev.entity) else {
197+
let Ok((disabled, checked)) = q_radio.get(ev.entity) else {
198198
// Not a radio button
199199
return;
200200
};
201201

202202
ev.propagate(false);
203203

204-
// Radio button is already checked
205-
if checked {
204+
// Radio button is disabled or already checked
205+
if disabled || checked {
206206
return;
207207
}
208208

0 commit comments

Comments
 (0)