NAME

Clay::UI::Events::OnBlur - fired at a widget that loses the focus

SYNOPSIS

use v5.22;
use warnings;
use feature 'signatures';
no warnings 'experimental::signatures';

use Object::Pad;
use Clay::UI;
use Clay::UI::Box;
use Clay::UI::Role::Interaction::Focusable;

class My::Panel :strict(params) :does(Clay::UI::Box) {}
class My::Input :strict(params)
	:does(Clay::UI::Box)
	:does(Clay::UI::Role::Interaction::Focusable)
{}

my $name  = My::Input->new(id => 'name');
my $email = My::Input->new(id => 'email');
my $root  = My::Panel->new(id => 'form');
$root->add_child($name, $email);
$name->on('OnBlur', sub ($event) {
	say 'focus left ', $event->target->id;
	return;
});

my $ui = Clay::UI->new(width => 400, height => 300, root => $root);
$ui->interaction->set_focused_widget($name);
$ui->interaction->set_focused_widget($email);   # prints "focus left name"

DESCRIPTION

OnBlur fires at the widget that had the focus, right after it lost it:

The widget no longer has the focus (is_focused is 0) when its listeners run. A widget gets OnBlur only after it got OnFocus. render never fires OnBlur by itself.

Name

'OnBlur'.

Received by

The widget that lost the focus.

Bubbling

Bubbles with Clay::UI::Enum::Bubble->IF_CONTINUE: the parent sees the event when the widget has no OnBlur listener or all its listeners return Clay::UI::Enum::Result->CONTINUE.

ACCESSORS

No payload. The inherited accessors (see Clay::UI::Events::Event): name is 'OnBlur', bubble_mode is IF_CONTINUE, target is the widget that lost the focus, current_target the widget whose listeners run right now, and handled_by and result tell where the event stopped.

CLASS METHODS

event_name

my $name = Clay::UI::Events::OnBlur->event_name;    # 'OnBlur'

Returns 'OnBlur', the event name listeners register for with on and the default name of a new event (see "event_name" in Clay::UI::Events::Event).

SEE ALSO

Clay::UI::Events::OnFocus, Clay::UI::Role::Interaction::Focusable, "FOCUS" in Clay::UI::Interaction, "REMOVED WIDGETS" in Clay::UI::Interaction.