Skip to content

Commit

Permalink
Nested dialogs (#1471)
Browse files Browse the repository at this point in the history
* Remove unused variable

* Check for closest model with correct id

* add preview for nested dialog

* exit dev workflow if overmind is not installed

* Add changeset
  • Loading branch information
koddsson authored Oct 10, 2022
1 parent 1c9e45a commit 5687beb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-goats-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Make sure nested dialogs behave correctly
3 changes: 1 addition & 2 deletions app/components/primer/alpha/modal_dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class ModalDialogElement extends HTMLElement {
#focusAbortController = new AbortController()
#abortController: AbortController | null = null
#openButton: HTMLButtonElement | undefined
#shouldTryLoadingFragment = true

get open() {
return this.hasAttribute('open')
Expand Down Expand Up @@ -67,7 +66,7 @@ export class ModalDialogElement extends HTMLElement {
'click',
event => {
const target = event.target as HTMLElement
const clickOutsideDialog = target.closest(this.tagName) !== this
const clickOutsideDialog = !target.closest(`#${this.getAttribute('id')}`)
const button = target?.closest('button')
// go over this logic:
if (!button) {
Expand Down
15 changes: 15 additions & 0 deletions previews/primer/alpha/dialog_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ def custom_header(title: "Test Dialog", subtitle: nil, button_text: "Show Dialog
show_divider: show_divider
})
end

# @label Nested dialog
#
# @param title [String] text
# @param subtitle [String] text
# @param button_text [String] text
# @param show_divider [Boolean] toggle
def nested_dialog(title: "Test Dialog", subtitle: nil, button_text: "Show Dialog", show_divider: true)
render_with_template(locals: {
title: title,
subtitle: subtitle,
button_text: button_text,
show_divider: show_divider
})
end
end
end
end
14 changes: 14 additions & 0 deletions previews/primer/alpha/dialog_preview/nested_dialog.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= render(Primer::Alpha::Dialog.new(id: "dialog-one", title: title, subtitle: subtitle, visually_hide_title: false)) do |d| %>
<% d.show_button { button_text } %>
<% d.body do %>
<p>Dialog One!</p>

<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
<%= render(Primer::Alpha::Dialog.new(id: "dialog-two", title: title, subtitle: subtitle, visually_hide_title: false)) do |d| %>
<% d.show_button { button_text } %>
<% d.body do %>
Dialog Two!
<% end %>
<% end %>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions script/dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
if ! command -v overmind &> /dev/null
then
echo "Please install overmind."
exit 1
fi

# Gems
Expand Down

0 comments on commit 5687beb

Please sign in to comment.