NAME

Term::Fabulous::Event::Select - The user opened or closed an item of an accordion, or chose a tab

SYNOPSIS

$accordion->on( Select => sub ($event) {
	my $item = $event->item;
	$status->text( $event->open ? 'Opened ' . $item->title : 'Closed ' . $item->title );
	return;
} );

$tabs->on( Select => sub ($event) {
	$status->text( 'Showing ' . $event->item->title );
	return;
} );

DESCRIPTION

A widget that lets the user pick one of its items fires Select on itself when the user does so:

  • A Term::Fabulous::Widget::Accordion, when the user opens or closes one of its items: with a click on the item's header, with Enter or Space while the header has the focus, or through $accordion->choose($index), which acts as the user does. Opening and closing from your program (open, close, open_all, close_all, $item->open(1)) fires nothing. When opening one item closes another, because the accordion allows one open item at a time, only the item the user acted on fires.

  • A Term::Fabulous::Widget::Tabs, when the user chooses another tab: with a click on it, with an arrow key, Home or End while the active tab has the focus, with Ctrl+PageUp or Ctrl+PageDown from anywhere inside, or through $tabs->choose($index). The item is the page now shown. Choosing from your program (select, $page->active(1)) fires nothing, and so does choosing the tab that is active already.

  • A Term::Fabulous::Widget::Tabs::Bar used on its own, likewise; the item is then the tab, a Term::Fabulous::Widget::Tabs::Button. Under a Tabs, the bar's event does not bubble past the Tabs, which fires its own with the page.

  • A Term::Fabulous::Widget::DocumentTabs, when the user clicks one of its tabs, the active one included, or an arrow at one of its ends, which chooses the next hidden tab on that side. The item is a copy of the tab's hash, as the DocumentTabs drew it, with the program's own keys. The DocumentTabs does not make the tab active itself: the program shows the document and sets active, which fires nothing.

It is a Clay::UI::Events::Event whose name is Select; listen for it with $widget->on( Select => sub ($event) { ... } ). It bubbles to the widget's ancestors like every event (see "Return values and bubbling" in Term::Fabulous::Manual::Events), and $event->target is the accordion, the Tabs, the bar or the DocumentTabs.

CONSTRUCTOR

new

my $event = Term::Fabulous::Event::Select->new( item => $item, index => 2, open => 1 );

The widgets build these events themselves; build one yourself only to test your listeners, or to fire Select from a widget of your own. Unknown parameters die, and so does an index that is not a non-negative integer.

item

Required. See "item".

index

Required. See "index".

open

A boolean. Default: 1. See "open".

METHODS

item

The widget the user chose: a Term::Fabulous::Widget::Accordion::Item, a Term::Fabulous::Widget::Tabs::Page (from a Tabs) or a Term::Fabulous::Widget::Tabs::Button (from a bar on its own). From a Term::Fabulous::Widget::DocumentTabs, the tab: a hash reference with title, modified, error, closable and the program's own keys (see "tabs" in Term::Fabulous::Widget::DocumentTabs).

index

Its position among the accordion's items or the tabs, from 0.

open

1 when the item was opened or the tab chosen, 0 when an accordion item was closed.

SEE ALSO

Term::Fabulous::Widget::Accordion, Term::Fabulous::Widget::Tabs, Term::Fabulous::Widget::Tabs::Bar, Term::Fabulous::Widget::DocumentTabs, "EVENTS" in Term::Fabulous::Manual::Events, "ACCORDIONS" in Term::Fabulous::Manual::Layout, "TABS" in Term::Fabulous::Manual::Layout.