Skip to content

fix: FluentkeyCode in repeated events make program slow #2881

@f4n0

Description

@f4n0

🐛 Bug Report

I've created a custom way to select data into a table (with ctrl and shift modifiers).
I've noticed a performance issue with the OnKeyDown handler.

In my case, the OnKeyDown is repeated too many times as the ctrl key is kept pressed.

💻 Repro or Code Sample

<FluentKeyCode OnKeyDown="@OnKeyDownAsync" OnKeyUp="OnKeyUp" IgnoreModifier="false" tabindex="0" 
               Only="[KeyCode.Function3, KeyCode.KeyF, KeyCode.Ctrl, KeyCode.Shift]" PreventDefault="true" StopPropagation="true">

.....

 private void OnKeyDownAsync(FluentKeyCodeEventArgs args)
 {
   
   Debug.WriteLine("OnKeyDown");
   if (MultipleSelectEnabled | ShiftModifierEnabled) return;
   if (args.Key == KeyCode.Ctrl)
   {
     MultipleSelectEnabled = true;
   }
   else if (args.Key == KeyCode.Shift)
   {
     ShiftModifierEnabled = true;
   }

 }

🤔 Expected Behavior

I would like a new Option to the FluentKeyCode: "StopRepeat" that will check the standard "Repeat" property. if they both are true, the JS will not execute any C# code.

😯 Current Behavior

The code provided, when ctrl key is pressed, the debug output is this:

14:10:57:631 OnKeyDown
14:10:58:129 OnKeyDown
14:10:58:129 OnKeyDown
14:10:58:129 OnKeyDown
14:10:58:129 OnKeyDown
14:10:58:366 OnKeyDown
14:10:58:366 OnKeyDown
14:10:58:366 OnKeyDown
14:10:58:631 OnKeyDown
14:10:58:631 OnKeyDown
14:10:58:631 OnKeyDown
14:10:58:631 OnKeyDown

and so on

💁 Possible Solution

use:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat

🔦 Context

🌍 Your Environment

  • OS & Device: [e.g. MacOS, iOS, Windows, Linux] on [iPhone 7, PC]
  • Browser [e.g. Microsoft Edge, Google Chrome, Apple Safari, Mozilla FireFox]
  • .NET and Fluent UI Blazor library Version [e.g. 8.0.2 and 4.4.1]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions