Skip to content

Commit 276d73f

Browse files
Another test case showing multiple aliases work
1 parent 52925ac commit 276d73f

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/Components/test/E2ETest/Tests/EventCustomArgsTest.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,40 @@ public void CanAliasBrowserEvent_StopPropagationIndependentOfNativeEvent()
108108
{
109109
var input = Browser.Exists(By.CssSelector("#test-event-target-child input"));
110110
Browser.FindElement(By.Id("register-custom-keydown")).Click();
111+
Browser.FindElement(By.Id("register-yet-another-keydown")).Click();
111112
Browser.FindElement(By.Id("custom-keydown-stop-propagation")).Click();
112113
SendKeysSequentially(input, "ab");
113114

114115
Browser.Equal(new[]
115116
{
116-
// The native event still bubbles up to its listener on an ancestor, but the
117-
// custom variant does not bubble up past the stopPropagation point
117+
// The native event still bubbles up to its listener on an ancestor, and
118+
// other aliased events still receive it, but the stopPropagation-ed
119+
// variant does not
118120
"Received native keydown event",
121+
"Yet another aliased event received: a",
119122
"Received native keydown event",
123+
"Yet another aliased event received: b",
124+
}, GetLogLines);
125+
126+
Assert.Equal("ab", input.GetAttribute("value"));
127+
}
128+
129+
[Fact]
130+
public void CanHaveMultipleAliasesForASingleBrowserEvent()
131+
{
132+
var input = Browser.Exists(By.CssSelector("#test-event-target-child input"));
133+
Browser.FindElement(By.Id("register-custom-keydown")).Click();
134+
Browser.FindElement(By.Id("register-yet-another-keydown")).Click();
135+
SendKeysSequentially(input, "ab");
136+
137+
Browser.Equal(new[]
138+
{
139+
"Received native keydown event",
140+
"You pressed: a",
141+
"Yet another aliased event received: a",
142+
"Received native keydown event",
143+
"You pressed: b",
144+
"Yet another aliased event received: b",
120145
}, GetLogLines);
121146

122147
Assert.Equal("ab", input.GetAttribute("value"));

src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@onkeydown="@(e => { LogMessage("Received native keydown event"); })"
99
@ontestevent="@HandleTestEvent"
1010
@onkeydown.testvariant="@HandleCustomKeyDown"
11+
@onkeydown.yetanother="@HandleYetAnotherKeyboardEvent"
1112
@oncustommouseover="@(e => { LogMessage("Received custom mouseover event"); })">
1213
Event target
1314
<div id="test-event-target-child" style="background: #afa; padding: 1em;">
@@ -44,6 +45,11 @@
4445
Register custom keydown event
4546
</button>
4647

48+
<button id="register-yet-another-keydown"
49+
onclick="Blazor.registerCustomEventType('keydown.yetanother', { browserEventName: 'keydown', createEventArgs: event => ({ youPressed: event.key }) })">
50+
Register yet another custom keyboard event
51+
</button>
52+
4753
<button id="register-custom-mouseover"
4854
onclick="Blazor.registerCustomEventType('custommouseover', { browserEventName: 'mouseover' })">
4955
Register custom mouseover event (which has no corresponding native listener)
@@ -88,4 +94,9 @@
8894
{
8995
LogMessage($"You pressed: {eventArgs.CustomKeyInfo}");
9096
}
97+
98+
void HandleYetAnotherKeyboardEvent(YetAnotherCustomKeyboardEventArgs eventArgs)
99+
{
100+
LogMessage($"Yet another aliased event received: {eventArgs.YouPressed}");
101+
}
91102
}

src/Components/test/testassets/BasicTestApp/EventCustomArgsTypes.cs

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace BasicTestApp.CustomEventTypesNamespace
55
{
66
[EventHandler("ontestevent", typeof(TestEventArgs), true, true)]
77
[EventHandler("onkeydown.testvariant", typeof(TestKeyDownEventArgs), true, true)]
8+
[EventHandler("onkeydown.yetanother", typeof(YetAnotherCustomKeyboardEventArgs), true, true)]
89
[EventHandler("oncustommouseover", typeof(EventArgs), true, true)]
910
public static class EventHandlers
1011
{
@@ -19,4 +20,9 @@ class TestKeyDownEventArgs : EventArgs
1920
{
2021
public string CustomKeyInfo { get; set; }
2122
}
23+
24+
class YetAnotherCustomKeyboardEventArgs : EventArgs
25+
{
26+
public string YouPressed { get; set; }
27+
}
2228
}

0 commit comments

Comments
 (0)