Skip to content

Commit

Permalink
v.3.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
jsakamoto committed Oct 1, 2023
1 parent 5c55fe8 commit 97871eb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion HotKeys2/Toolbelt.Blazor.HotKeys2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>3.1.0-preview.2</Version>
<Version>3.1.0</Version>
<Copyright>Copyright © 2022-2023 J.Sakamoto, Mozilla Public License 2.0</Copyright>
<Authors>J.Sakamoto</Authors>
<RepositoryType>git</RepositoryType>
Expand Down
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ this.HotKeysContext = this.HotKeys.CreateContext()

## Supported Blazor versions

This library suppots ASP.NET Core Blazor version 6.0, 7.0, or later.
This library suppots ASP.NET Core Blazor version 6.0, 7.0, 8.0 or later.

## How to install and use?

Expand Down Expand Up @@ -78,17 +78,17 @@ Please remember that you have to keep the `HotKeys Context` object in the compon
```csharp
@code {

HotKeysContext HotKeysContext;
private HotKeysContext? HotKeysContext;

protected override void OnInitialized()
{
this.HotKeysContext = this.HotKeys.CreateContext()
.Add(ModCode.Ctrl|ModCode.Shift, Code.A, FooBar, "do foo bar.")
.Add(ModCode.Ctrl|ModCode.Shift, Code.A, FooBar, new() { Description = "do foo bar." })
.Add(...)
...;
}

void FooBar() // 👈 This will be invoked when Ctrl+Shift+A typed.
private void FooBar() // 👈 This will be invoked when Ctrl+Shift+A typed.
{
...
}
Expand All @@ -109,7 +109,7 @@ Please remember that you have to keep the `HotKeys Context` object in the compon
...
public void Dispose()
{
this.HotKeysContext.Dispose(); // 👈 1. Add this
this.HotKeysContext?.Dispose(); // 👈 1. Add this
}
}
```
Expand All @@ -124,49 +124,60 @@ The complete source code (.razor) of this component is bellow.

@code {

HotKeysContext HotKeysContext;
private HotKeysContext? HotKeysContext;

protected override void OnInitialized()
{
this.HotKeysContext = this.HotKeys.CreateContext()
.Add(ModCode.Ctrl|ModCode.Shift, Code.A, FooBar, "do foo bar.")
.Add(ModCode.Ctrl|ModCode.Shift, Code.A, FooBar, new() { Description = "do foo bar." })
}

void FooBar()
private void FooBar()
{
// Do something here.
}

public void Dispose()
{
this.HotKeysContext.Dispose();
this.HotKeysContext?.Dispose();
}
}
```
### How to enable / disable hotkeys depending on which element has focus

You can specify enabling/disabling hotkeys depending on which kind of element has focus at the hotkeys registration via a combination of the `Exclude` flags in optional arguments of the `HotKeysContext.Add()` method.
You can specify enabling/disabling hotkeys depending on which kind of element has focus at the hotkeys registration via a combination of the `Exclude` flags in the property of the option object argument of the `HotKeysContext.Add()` method.

By default, the `Exclude` flags argument is the following combination.
The default value of the option object's `Exclude` flag property is the following combination.

```csharp
Exclude.InputText | Exclude.InputNonText | Exclude.TextArea
```

This means, by default, hotkeys are disabled when the focus is in `<input>` (with any `type`) or `<textarea>` elements.
This means hotkeys are disabled when the focus is in `<input>` (with any `type`) or `<textarea>` elements by default.

If you want to enable hotkeys even when an `<input type="text"/>` has focus, you can do it as below.
If you want to enable hotkeys even when an `<input type="text"/>` has focus, you can implement it as below.

```csharp
... this.HotKeys.CreateContext()
.Add(Code.A, OnKeyDownA, "...",
// 👇 Specify the "exclude" argument.
exclude: Exclude.InputNonText | Exclude.TextArea)
.Add(Code.A, OnKeyDownA, new() {
// 👇 Specify the "Exclude" property of the options.
Exclude = Exclude.InputNonText | Exclude.TextArea })
...
```

You can also specify the elements that are disabled hotkeys by CSS query selector string via the `ExcludeSelector` property of the options object.

```csharp
... this.HotKeys.CreateContext()
.Add(Code.A, OnKeyDownA, new() {
// 👇 Specify the CSS query selector to the "ExcludeSelector" property of the options.
ExcludeSelector = ".disabled-hotkeys-area" })
...
```

And you can specify the `Exclude.ContentEditable` to register the unavailable hotkey when any "contenteditable" applied elements have focus.


## `Code` vs. `Key` - which way should I use to?

There are two ways to register hotkeys in the `HotKeysContext`.
Expand Down
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v.3.1.0
- Improve: Exclude by a custom CSS query selector.
- Improve: Add .NET 8 support.

v.3.0.0
- Improve: explicit calling StateHasChanged is no longer needed inside hotkey handler methods.

Expand Down
2 changes: 1 addition & 1 deletion SampleSites/Components/SampleSite.Components.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Toolbelt.Blazor.HotKeys2" Version="3.1.0-preview.2" />
<PackageReference Include="Toolbelt.Blazor.HotKeys2" Version="3.1.0" />
<!--<ProjectReference Include="..\..\HotKeys2\Toolbelt.Blazor.HotKeys2.csproj" />-->
</ItemGroup>

Expand Down

0 comments on commit 97871eb

Please sign in to comment.