BottomSheet
Relationship to Modal and Drawer
Section titled “Relationship to Modal and Drawer”All three (Modal, Drawer, BottomSheet) implement nav.ModalComponent with identical lifecycle behavior. Choose based on layout intent:
- Modal — centered dialog
- Drawer — right/left edge panel
- BottomSheet — bottom-anchored panel
Usage
sheet := components.NewBottomSheet(components.BottomSheetConfig{ Title: "Quick Actions", Height: 12, Backdrop: true,}). SetContent(tview.NewBox()). SetHints([]components.KeyHint{ {Key: "Esc", Description: "Close"}, })
fmt.Println(sheet != nil)Methods
| Method | Signature | Description |
|---|---|---|
Close | func (b *BottomSheet) Close() | Close triggers the close callback. |
GetBehavior | func (b *BottomSheet) GetBehavior() ModalBehavior | GetBehavior returns the bottom sheet's behavior configuration. |
GetHintBar | func (b *BottomSheet) GetHintBar() *KeyHintBar | GetHintBar returns the hint bar for direct manipulation. |
GetPanel | func (b *BottomSheet) GetPanel() *Panel | GetPanel returns the bottom sheet's panel for customization. |
Hints | func (b *BottomSheet) Hints() []KeyHint | Hints returns key binding hints for this bottom sheet. |
ModalBehavior | func (b *BottomSheet) ModalBehavior() ModalBehavior | ModalBehavior implements nav.Modal. |
Name | func (b *BottomSheet) Name() string | Name returns the bottom sheet title for breadcrumbs. |
OnDismiss | func (b *BottomSheet) OnDismiss() bool | OnDismiss implements nav.Modal. |
SetBehavior | func (b *BottomSheet) SetBehavior(beh ModalBehavior) *BottomSheet | SetBehavior configures the bottom sheet's behavior. |
SetContent | func (b *BottomSheet) SetContent(content tview.Primitive) *BottomSheet | SetContent sets the bottom sheet's main content. |
SetDismissOnEsc | func (b *BottomSheet) SetDismissOnEsc(dismiss bool) *BottomSheet | SetDismissOnEsc sets whether Escape key dismisses the bottom sheet. |
SetFocusOnShow | func (b *BottomSheet) SetFocusOnShow(p tview.Primitive) *BottomSheet | SetFocusOnShow sets a specific primitive to focus when the bottom sheet is shown. |
SetHeight | func (b *BottomSheet) SetHeight(height int) *BottomSheet | SetHeight updates the sheet height and rebuilds layout. |
SetHints | func (b *BottomSheet) SetHints(hints []KeyHint) *BottomSheet | SetHints sets the key hints displayed at bottom. |
SetOnClose | func (b *BottomSheet) SetOnClose(fn func()) *BottomSheet | SetOnClose sets callback when bottom sheet closes. |
SetOnDismiss | func (b *BottomSheet) SetOnDismiss(fn func() bool) *BottomSheet | SetOnDismiss sets a handler called before the bottom sheet is dismissed. Return false from the handler to cancel the dismiss. |
Start | func (b *BottomSheet) Start() | Start is called when the bottom sheet becomes active. |
Stop | func (b *BottomSheet) Stop() | Stop is called when the bottom sheet becomes inactive. |
Types
type BottomSheetConfig struct BottomSheetConfig configures bottom sheet dimensions and behavior. | Field | Type | Description |
|---|---|---|
Title | string | |
Height | int | Fixed height (0 = auto-size to content) |
Backdrop | bool | Draw semi-transparent background above the sheet |
type KeyHint struct KeyHint represents a single key binding hint. | Field | Type | Description |
|---|---|---|
Key | string | e.g., "Enter", "Esc", "Space", "j/k" |
Description | string | e.g., "Select", "Close", "Toggle" |
type KeyHintBar struct KeyHintBar displays key hints in a pill style at the bottom of views/modals. | Field | Type | Description |
|---|---|---|
Hints | []KeyHint |
type ModalBehavior struct ModalBehavior configures how a modal handles input and lifecycle.
This is a copy of nav.ModalBehavior to avoid import cycles.
The values are copied when implementing nav.ModalComponent. | Field | Type | Description |
|---|---|---|
CapturesAllInput | bool | CapturesAllInput prevents input from reaching underlying views. |
DismissOnEsc | bool | DismissOnEsc automatically dismisses the modal when Escape is pressed. |
RestoreFocusOnDismiss | bool | RestoreFocusOnDismiss returns focus to the previous component when dismissed. |
Backdrop | bool | Backdrop draws a semi-transparent overlay behind the modal. |
BlockUntilDismissed | bool | BlockUntilDismissed prevents other stack operations until this modal is dismissed. |
type Panel Panel is a container with rounded borders and optional title.
It delegates focus and input handling to its content.