Summary
As react
and vue
packages support nested dialogs, we should introduce the same concept.
example in react
The concept assumes that a parent dialog cannot be closed when at least one child dialog is opened. By clicking outside (ESC, on overlay) we only close the dialog which was opened lastly (leaf).
Detailed design
To achieve this goal, we need sort of counter
/ state
in each dialog, which will keep track of information that at least one children dialog is opened. For communication between parent - child, vue uses concept of inject/provider, link.
In practice they don't have to pass explicitly properties to child component in template.
As in ember we don't have similar mechanism, and we would like to keep headless API as much unified as possible, I propose to use yield emberism. We can yield another value from <Dialog>
component, e.g. Nested
and then we can pass this.element
to its child. Example:
{{yield (hash
isOpen=@isOpen
onClose=@onClose
Overlay=(
component "dialog/-overlay"
...
)
...
Nested=(component "dialog" parentDialog=this)
)}}
then nested dialog use:
<Dialog
@isOpen={{state.isOpen}}
@onClose={{set state.isOpen false}}
as |dialog|
>
Parent dialog
<dialog.Nested>
child dialog
</dialog.Nested>
</Dialog>
Drawbacks
API is not 100% match, compare to react
and vue
where they used just <Dialog>
inside another <Dialog>
Alternatives
I was thinking about service injected to all dialogs, then when a component is mounted, the dialog is registered in service. Each time when new dialog is registered, the service iterates on opened dialogs and checks relationship parent - child. Open question is: as long as we use portals (dialogs are render as siblings) we cannot rely on DOM nodes, native events for checking parent - child. @achambers you said about some solution for this problem - I cannot remember details - can you remind me ?
@GavinJoyce @alexlafroscia
Would be wonderful to see your voices here.