-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add @bind-open support for details and dialog elements #64654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -122,8 +122,8 @@ namespace Microsoft.AspNetCore.Components.Web; | |||||
| [EventHandler("onreadystatechange", typeof(EventArgs), true, true)] | ||||||
| [EventHandler("onscroll", typeof(EventArgs), true, true)] | ||||||
|
|
||||||
| // <details> | ||||||
| [EventHandler("ontoggle", typeof(EventArgs), true, true)] | ||||||
| // <details> and elements with popover attribute | ||||||
|
||||||
| // <details> and elements with popover attribute | |
| // <details>, <dialog>, and elements with popover attribute |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,56 @@ public void CanBindCheckbox_InitiallyChecked() | |
| Browser.Equal("True", () => boundValue.Text); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CanBindDetailsElement_InitiallyClosed() | ||
| { | ||
| var target = Browser.Exists(By.Id("details-initially-closed")); | ||
| var boundValue = Browser.Exists(By.Id("details-initially-closed-value")); | ||
| var toggleButton = Browser.Exists(By.Id("details-initially-closed-toggle")); | ||
| Assert.Null(target.GetDomAttribute("open")); | ||
| Assert.Equal("False", boundValue.Text); | ||
|
|
||
| // Click to expand; verify value is updated | ||
| target.FindElement(By.TagName("summary")).Click(); | ||
| Browser.NotEqual(null, () => target.GetDomAttribute("open")); | ||
| Browser.Equal("True", () => boundValue.Text); | ||
|
|
||
| // Click to collapse; verify value is updated | ||
| target.FindElement(By.TagName("summary")).Click(); | ||
| Browser.Equal(null, () => target.GetDomAttribute("open")); | ||
| Browser.Equal("False", () => boundValue.Text); | ||
|
|
||
| // Modify data programmatically; verify details is updated | ||
| toggleButton.Click(); | ||
| Browser.NotEqual(null, () => target.GetDomAttribute("open")); | ||
| Browser.Equal("True", () => boundValue.Text); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CanBindDetailsElement_InitiallyOpen() | ||
| { | ||
| var target = Browser.Exists(By.Id("details-initially-open")); | ||
| var boundValue = Browser.Exists(By.Id("details-initially-open-value")); | ||
| var toggleButton = Browser.Exists(By.Id("details-initially-open-toggle")); | ||
| Assert.NotNull(target.GetDomAttribute("open")); | ||
| Assert.Equal("True", boundValue.Text); | ||
|
|
||
| // Click to collapse; verify value is updated | ||
| target.FindElement(By.TagName("summary")).Click(); | ||
| Browser.Equal(null, () => target.GetDomAttribute("open")); | ||
| Browser.Equal("False", () => boundValue.Text); | ||
|
|
||
| // Click to expand; verify value is updated | ||
| target.FindElement(By.TagName("summary")).Click(); | ||
| Browser.NotEqual(null, () => target.GetDomAttribute("open")); | ||
| Browser.Equal("True", () => boundValue.Text); | ||
|
|
||
| // Modify data programmatically; verify details is updated | ||
| toggleButton.Click(); | ||
| Browser.Equal(null, () => target.GetDomAttribute("open")); | ||
| Browser.Equal("False", () => boundValue.Text); | ||
| } | ||
|
Comment on lines
+197
to
+245
|
||
|
|
||
| [Fact] | ||
| public void CanBindSelect() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title mentions "Add @bind-open support for details and dialog elements", and the technical notes in the PR description explain that toggle events are fired by both
<details>and<dialog>elements. However, onlyBindElementattributes for thedetailselement are added here. To fully support the stated functionality, you should also add:Without these attributes,
@bind-openwill not work for<dialog>elements despite the infrastructure being in place.