Keyboard Interaction

13 Jun 20231 minute to read

With the keyboard navigation enabled in the NumericTextBox control, it is possible to control the actions with the provided shortcut keys. Almost all the NumericTextBox functionality that are done through mouse can be controlled with shortcut keys.

The various keyboard shortcuts available within the NumericTextBox control are discussed in the following table.

Keyboard Shortcuts

Shortcut Key Description

Access key

+ j
Focuses the control
Up Increments the value
Down Decrements the value
Tab Focus the next element

Configuring Keyboard Navigation

The following steps explain the implementation of keyboard interaction in NumericTextBox.

In the View page add NumericTextBox helper. Set the access key property to the NumericTextBox for focusing the control while key is pressed. We need to use ‘HtmlAttributes’ property to add the ”access key” attribute to the Editor elements. ‘HtmlAttributes’ property is used to add HTML attributes like, id, class etc.. to the components. We need to use IDictionary<string,object> to specify the HTML attributes.

  • CSHTML
  • @{IDictionary<string, object> numericAttribute = new Dictionary<string, object>();
    
      numericAttribute.Add("accesskey", "j");
    
    }
    
    @Html.EJ().NumericTextbox("numeric").Name("numeric").Value("11").HtmlAttributes(numericAttribute)

    Run the above example and press Access key + j key to focus the NumericTextBox widget. Perform provided functionality by using keyboard shortcuts.