pub struct Dropdown;Expand description
A searchable dropdown selection component.
This component provides a filterable dropdown menu for selecting a single option from a list. Users can type to filter options, then navigate and select using keyboard controls.
§Features
- Case-insensitive “contains” matching
- Keyboard navigation through filtered results
- Selection from existing options only
- Filter clears on close/confirm
§Keyboard Navigation
The dropdown itself doesn’t handle keyboard events directly. Your application should map:
- Characters to
DropdownMessage::Insert - Backspace to
DropdownMessage::Backspace - Down arrow to
DropdownMessage::Down - Up arrow to
DropdownMessage::Up - Enter to
DropdownMessage::Confirm - Escape to
DropdownMessage::Close
§Visual States
Closed (no selection):
┌──────────────────────┐
│ Search... ▼ │
└──────────────────────┘Closed (with selection):
┌──────────────────────┐
│ Apple ▼ │
└──────────────────────┘Open (with filter):
┌──────────────────────┐
│ app█ ▲ │
├──────────────────────┤
│ > Apple │ ← highlighted
│ Pineapple │
└──────────────────────┘§Example
use envision::component::{Dropdown, DropdownMessage, DropdownOutput, DropdownState, Component};
let mut state = DropdownState::new(vec!["Apple", "Banana", "Cherry"]);
// Open and filter
Dropdown::update(&mut state, DropdownMessage::Open);
Dropdown::update(&mut state, DropdownMessage::Insert('a'));
// Navigate and select
Dropdown::update(&mut state, DropdownMessage::Down);
let output = Dropdown::update(&mut state, DropdownMessage::Confirm);
assert_eq!(output, Some(DropdownOutput::Selected("Banana".to_string()))); // BananaTrait Implementations§
Source§impl Component for Dropdown
impl Component for Dropdown
Source§type State = DropdownState
type State = DropdownState
The component’s internal state type. Read more
Source§type Message = DropdownMessage
type Message = DropdownMessage
Messages this component can receive. Read more
Source§type Output = DropdownOutput
type Output = DropdownOutput
Messages this component can emit to its parent. Read more
Source§fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
Update component state based on a message. Read more
Source§fn handle_event(state: &Self::State, event: &Event) -> Option<Self::Message>
fn handle_event(state: &Self::State, event: &Event) -> Option<Self::Message>
Maps an input event to a component message. Read more
Source§fn view(state: &Self::State, frame: &mut Frame<'_>, area: Rect, theme: &Theme)
fn view(state: &Self::State, frame: &mut Frame<'_>, area: Rect, theme: &Theme)
Render the component to the given area. Read more
Auto Trait Implementations§
impl Freeze for Dropdown
impl RefUnwindSafe for Dropdown
impl Send for Dropdown
impl Sync for Dropdown
impl Unpin for Dropdown
impl UnsafeUnpin for Dropdown
impl UnwindSafe for Dropdown
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more