Class: PhlexKit::AlertDialogContent
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::AlertDialogContent
- Defined in:
- app/components/phlex_kit/alert_dialog/alert_dialog_content.rb
Overview
The modal body, held in a and cloned into on open. The
cloned div carries its own phlex-kit--alert-dialog controller so Cancel
(#dismiss) can remove it. Holds Header + Footer. Caller **attrs land on the
visible panel (the role="alertdialog" div), not the inert .
See alert_dialog.rb.
Constant Summary collapse
- SIZES =
size => panel modifier; :sm is shadcn's compact variant.
{ default: nil, sm: "sm" }.freeze
Instance Method Summary collapse
-
#initialize(size: :default, **attrs) ⇒ AlertDialogContent
constructor
A new instance of AlertDialogContent.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(size: :default, **attrs) ⇒ AlertDialogContent
Returns a new instance of AlertDialogContent.
11 12 13 14 |
# File 'app/components/phlex_kit/alert_dialog/alert_dialog_content.rb', line 11 def initialize(size: :default, **attrs) @size = size.to_sym @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/components/phlex_kit/alert_dialog/alert_dialog_content.rb', line 16 def view_template(&block) template(data: { phlex_kit__alert_dialog_target: "content" }) do # The clone's controller listens for keydown on `document` while open # (an element-scoped listener dies the moment focus escapes to <body>); # mousedown on the overlay is prevented so a stray click can't move # focus out of the trap. tabindex="-1" on the panel is the focus # fallback when the dialog has no focusable children. # data-pk-overlay-clone is a common marker read across clone-based # overlay families (see #topmost in alert_dialog_controller.js) so # Escape resolves to whichever overlay is actually topmost, even when # a different overlay type (e.g. a Sheet) is nested/stacked on top. div(data: { controller: "phlex-kit--alert-dialog", pk_overlay_clone: "" }) do div(class: "pk-alert-dialog-overlay", "aria-hidden": "true", data: { action: "mousedown->phlex-kit--alert-dialog#overlayMousedown" }) panel_attrs = { class: [ "pk-alert-dialog-panel", fetch_option(SIZES, @size, :size) ].compact.join(" ") } # Defaults only when the caller didn't supply their own — `mix` # would fuse role="alertdialog dialog" / aria-modal="true false" / # tabindex="-1 0" instead of overriding. panel_attrs[:role] = "alertdialog" unless @attrs.key?(:role) || @attrs.key?("role") panel_attrs[:"aria-modal"] = "true" unless aria_key_set?(:modal) panel_attrs[:tabindex] = "-1" unless @attrs.key?(:tabindex) || @attrs.key?("tabindex") div(**mix(panel_attrs, @attrs), &block) end end end |