-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toggle Headless UI components on button click (#8)
* toggle menu, listbox and popover when clicking the button instead of just opening it * add tests for #7
- Loading branch information
1 parent
589fe64
commit 9b60a93
Showing
6 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
46 changes: 46 additions & 0 deletions
46
tests/Ignis.Tests.Components.HeadlessUI/ListboxTests.razor
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@inherits TestContext | ||
|
||
@code | ||
{ | ||
[Fact] | ||
public void Button_OnClick() | ||
{ | ||
Services.AddIgnis(); | ||
Services.AddSingleton<IHostContext, TestHostContext>(); | ||
|
||
JSInterop.Mode = JSRuntimeMode.Loose; | ||
|
||
var cut = Render(@<Listbox TValue="object"> | ||
<ListboxButton> | ||
</ListboxButton> | ||
</Listbox>); | ||
|
||
cut.Find("button").Click(); | ||
|
||
var listbox = cut.FindComponent<Listbox<object>>(); | ||
Assert.True(listbox.Instance.IsOpen); | ||
|
||
cut.Find("button").Click(); | ||
|
||
Assert.False(listbox.Instance.IsOpen); | ||
} | ||
|
||
[Fact] | ||
public void Button_OnClick_PreventDefault() | ||
{ | ||
Services.AddIgnis(); | ||
Services.AddSingleton<IHostContext, TestHostContext>(); | ||
|
||
JSInterop.Mode = JSRuntimeMode.Loose; | ||
|
||
var cut = Render(@<Listbox TValue="object"> | ||
<ListboxButton OnClick="e => e.PreventDefault()"> | ||
</ListboxButton> | ||
</Listbox>); | ||
|
||
cut.Find("button").Click(); | ||
|
||
var listbox = cut.FindComponent<Listbox<object>>(); | ||
Assert.False(listbox.Instance.IsOpen); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@inherits TestContext | ||
|
||
@code | ||
{ | ||
[Fact] | ||
public void Button_OnClick() | ||
{ | ||
Services.AddIgnis(); | ||
Services.AddSingleton<IHostContext, TestHostContext>(); | ||
|
||
JSInterop.Mode = JSRuntimeMode.Loose; | ||
|
||
var cut = Render(@<Menu> | ||
<MenuButton> | ||
</MenuButton> | ||
</Menu>); | ||
|
||
cut.Find("button").Click(); | ||
|
||
var menu = cut.FindComponent<Menu>(); | ||
Assert.True(menu.Instance.IsOpen); | ||
|
||
cut.Find("button").Click(); | ||
|
||
Assert.False(menu.Instance.IsOpen); | ||
} | ||
|
||
[Fact] | ||
public void Button_OnClick_PreventDefault() | ||
{ | ||
Services.AddIgnis(); | ||
Services.AddSingleton<IHostContext, TestHostContext>(); | ||
|
||
JSInterop.Mode = JSRuntimeMode.Loose; | ||
|
||
var cut = Render(@<Menu> | ||
<MenuButton OnClick="e => e.PreventDefault()"> | ||
</MenuButton> | ||
</Menu>); | ||
|
||
cut.Find("button").Click(); | ||
|
||
var menu = cut.FindComponent<Menu>(); | ||
Assert.False(menu.Instance.IsOpen); | ||
} | ||
} |
This file contains 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