HTML::Object::DOM::Element::Slot - HTML Object DOM Slot Class
use HTML::Object::DOM::Element::Slot; my $slot = HTML::Object::DOM::Element::Slot->new || die( HTML::Object::DOM::Element::Slot->error, "\n" );
v0.2.0
This interface of the Shadow DOM API enables access to the name and assigned nodes of an HTML slot element.
slot
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+ | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Slot | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+
Inherits properties from its parent HTML::Object::DOM::Element
A string used to get and set the slot's name.
Example:
my $slots = this->shadowRoot->querySelectorAll('slot'); $slots->[1]->addEventListener( slotchange => sub { my $nodes = $slots->[1]->assignedNodes(); say( 'Element in Slot "' . $slots->[1]->name . '" changed to "' . $nodes->[0]->outerHTML . '".'); });
See also Mozilla documentation
Inherits methods from its parent HTML::Object::DOM::Element
Under perl environment, this always returns undef.
undef
Under JavaScript, this sets the manually assigned nodes for this slot to the given nodes.
sub UpdateDisplayTab { my( $elem, $tabIdx ) = @_; my $shadow = $elem->shadowRoot; my $slot = $shadow->querySelector( 'slot' ); my $panels = $elem->querySelectorAll( 'tab-panel' ); if( $panels->length && $tabIdx && $tabIdx <= $panels->length ) { $slot->assign( $panels->[ $tabIdx - 1 ] ); } else { $slot->assign(); } }
Under JavaScript, this returns a sequence of the elements assigned to this slot (and no other nodes). If the flatten option is set to true, it also returns the assigned elements of any other slots that are descendants of this slot. If no assigned nodes are found, it returns the slot's fallback content.
my $slots = this->shadowRoot->querySelector('slot'); my $elements = $slots->assignedElements({ flatten => 1 });
Under JavaScript, this returns a sequence of the nodes assigned to this slot, and if the flatten option is set to true, the assigned nodes of any other slots that are descendants of this slot. If no assigned nodes are found, it returns the slot's fallback content.
my $slots = this->shadowRoot->querySelectorAll('slot'); $slots->[1]->addEventListener( slotchange => sub { my $nodes = $slots->[1]->assignedNodes(); say( 'Element in Slot "' . $slots->[1]->name . '" changed to "' . $nodes->[0]->outerHTML . '".' ); });
Event listeners for those events can also be found by prepending on before the event type:
on
For example, slotchange event listeners can be set also with onslotchange method:
slotchange
onslotchange
$e->onslotchange(sub{ # do something }); # or as an lvalue method $e->onslotchange = sub{ # do something };
Fired on an HTMLSlotElement instance (<slot> element) when the node(s) contained in that slot change.
Jacques Deguest <jack@deguest.jp>
Mozilla documentation, Mozilla documentation on slot element
Copyright(c) 2022 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install HTML::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Object
CPAN shell
perl -MCPAN -e shell install HTML::Object
For more information on module installation, please visit the detailed CPAN module installation guide.