Skip to content

Commit fc20d7e

Browse files
authored
Raise keyboard events using special keys
Raise keyboard events using special keys
2 parents 64dee51 + 5b16d96 commit fc20d7e

File tree

5 files changed

+1387
-3
lines changed

5 files changed

+1387
-3
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ List of new features.
1414
- Two new overloads to the `RenderFragment()` and `ChildContent()` component parameter factory methods have been added that takes a `RenderFragment` as input. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
1515
- Added a `ComponentParameterCollection` type. The `ComponentParameterCollection` is a collection of component parameters, that knows how to turn those components parameters into a `RenderFragment`, which will render a component and pass any parameters inside the collection to that component. That logic was spread out over multiple places in bUnit, and is now owned by the `ComponentParameterCollection` type. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
1616
- Added additional placeholder services for `NavigationManager`, `HttpClient`, and `IStringLocalizer`, to make it easier for users to figure out why a test is failing due to missing service registration before rendering a component. By [@joro550](https://github.com/joro550) in [#223](https://github.com/egil/bUnit/pull/223).
17+
- Added `Key` class that represents a keyboard key and helps to avoid constructing `KeyboardEventArgs` object manually. The key can be passed to `KeyPress`, `KeyDown`, or `KeyUp` helper methods to raise keyboard events. The `Key` class provides static special keys or can be obtained from character or string. Keys can be combined with key modifiers: `Key.Enter + Key.Alt`.
18+
19+
For example, this makes it easier to trigger keyboard events on an element:
20+
21+
```csharp
22+
var cut = ctx.RenderComponent<ComponentWithKeyboardEvents>();
23+
var element = cut.Find("input");
24+
25+
element.KeyDown(Key.Enter + Key.Control); // Triggers onkeydown event with Ctrl + Enter
26+
element.KeyUp(Key.Control + Key.Shift + 'B'); // Triggers onkeyup event with Ctrl + Shift + B
27+
element.KeyPress('1'); // Triggers onkeypress event with key 1
28+
element.KeyDown(Key.Alt + "<"); // Triggers onkeydown event with Alt + <
29+
```
30+
By [@duracellko](https://github.com/duracellko) in [#101](https://github.com/egil/bUnit/issues/101).
1731

1832
### Changed
1933
List of changes in existing functionality.

0 commit comments

Comments
 (0)