Repository navigation
Special-case <dialog> element [open] attribute - #165
Open
seanpdoyle wants to merge 1 commit into
Open
seanpdoyle wants to merge 1 commit into
seanpdoyle wants to merge 1 commit into
Conversation
According to the MDN documentation for the [HTMLDialogElement.open()][] attribute: > *Warning*: While the open property is technically not read-only and can > be set directly, doing so is strongly discouraged by the HTML > specification, as it can break normal dialog interactions in unexpected > ways. For example, the `close` event won't fire when programmatically > setting `open` to `false`, and subsequent calls to the `close()` and > `requestClose()` methods will have no effect. Instead, it's better to > use methods such as `show()`, `showModal()`, `close()`, and > `requestClose()` to change the value of the `open` attribute. > > -- MDN documentation for `HTMLDialogElement.open` property value Prior to this commit, `Idiomorph.morph` invocations that resulted in the removal of the `[open]` attribute violated this guidance. If the `[open]` attribute was present (regardless of its provenance: `HTMLDialogElement.show()`, `HTMLDialogElement.showModal()`, or being rendered with `[open]`), the morph would remove the attribute itself in a way that circumvents the internal state management of the `<dialog>` element. This commit introduces a special-case conditional that skips the explicit removal of the `[open]` in favor of invoking [HTMLDialogElement.close()][] directly. Since morphs occur without end-user involvement, `.close()` is invoked rather than [HTMLDialogElement.requestClose()][]. [HTMLDialogElement.open()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/open#value [HTMLDialogElement.close()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/close [HTMLDialogElement.requestClose()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/requestClose
Contributor
Author
|
@botandrose This proposal is motivated by hotwired/turbo#1239 and hotwired/turbo#1592. Turbo is currently capable of owning this behavior, but given the explicit guidance provided by the MDN documentation, there is an opportunity to encode this decision making process directly into Idiomorph itself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The HTML specification explicitly highlights the risk of removing the
[open]attribute directly:Similarly, according to the MDN documentation for the HTMLDialogElement.open() attribute:
Prior to this commit,
Idiomorph.morphinvocations that resulted in the removal of the[open]attribute violated this guidance. If the[open]attribute was present (regardless of its provenance:HTMLDialogElement.show(),HTMLDialogElement.showModal(), or being rendered with[open]), the morph would remove the attribute itself in a way that circumvents the internal state management of the<dialog>element.This commit introduces a special-case conditional that skips the explicit removal of the
[open]in favor of invoking HTMLDialogElement.close() directly. Since morphs occur without end-user involvement,.close()is invoked rather than HTMLDialogElement.requestClose().