Skip to content

Commit 74ee508

Browse files
committed
fix(dropdown::multi): panic on missing paragraph
1 parent 2b9e0c0 commit 74ee508

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/widget/dropdown/multi/widget.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,17 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static
443443
}
444444

445445
super::menu::OptionElement::Option((option, item)) => {
446-
let selection_index = state
447-
.selections
448-
.iter()
449-
.position(|(i, _)| i == item)
450-
.expect("selection missing from state");
446+
let selection_index = state.selections.iter().position(|(i, _)| i == item);
447+
448+
let selection_index = match selection_index {
449+
Some(index) => index,
450+
None => {
451+
state
452+
.selections
453+
.push((item.clone(), crate::Paragraph::new()));
454+
state.selections.len() - 1
455+
}
456+
};
451457

452458
let paragraph = &mut state.selections[selection_index].1;
453459

0 commit comments

Comments
 (0)