# JavaScript Utilities


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Configuration Injection

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L18"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_config_from_dict

``` python

def js_config_from_dict(
    config:dict[str, Any], # Python dict to convert
    var_name:str='cfg', # JavaScript variable name
)->str: # JavaScript const declaration

```

*Generate JavaScript const declaration from Python dict.*

``` python
# Test config generation
result = js_config_from_dict({"key": "value", "num": 42})
assert "const cfg" in result
assert '"key"' in result
assert '"value"' in result
```

## Input Detection

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L27"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_input_detection

``` python

def js_input_detection(
    selector:str="input, textarea, select, [contenteditable='true']", # CSS selector for input elements
)->str: # JavaScript function definition

```

*Generate JavaScript function to detect if input element is focused.*

``` python
# Test input detection
result = js_input_detection()
assert "function isInputFocused" in result
assert "target.matches" in result
```

## Focus Ring Helpers

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L40"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_focus_ring_helpers

``` python

def js_focus_ring_helpers(
    default_classes:tuple[str, ...]=('ring-2', 'ring-primary'), # default focus ring CSS classes
)->str: # JavaScript function definitions

```

*Generate JavaScript functions for adding/removing focus ring classes.*

``` python
# Test focus ring helpers
result = js_focus_ring_helpers()
assert "function addFocusRing" in result
assert "function removeFocusRing" in result
assert str(ring(2)) in result
assert str(ring_dui.primary) in result
```

## Scroll Into View

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L60"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_scroll_into_view

``` python

def js_scroll_into_view(
    behavior:str='smooth', # "smooth" or "auto"
    block:str='nearest', # "start", "center", "end", "nearest"
)->str: # JavaScript function definition

```

*Generate JavaScript function to scroll element into view.*

``` python
# Test scroll helper
result = js_scroll_into_view()
assert "function scrollToElement" in result
assert "scrollIntoView" in result
assert "smooth" in result
```

## Hidden Input Update

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L76"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_hidden_input_update

``` python

def js_hidden_input_update(
    
)->str: # JavaScript function definition

```

*Generate JavaScript function to update hidden input values.*

``` python
# Test hidden input update
result = js_hidden_input_update()
assert "function updateHiddenInput" in result
assert "function updateHiddenInputs" in result
```

## Button Click Trigger

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L94"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_trigger_click

``` python

def js_trigger_click(
    
)->str: # JavaScript function definition

```

*Generate JavaScript function to programmatically click a button.*

``` python
# Test trigger click
result = js_trigger_click()
assert "function triggerClick" in result
assert "button.click()" in result
```

## Data Attribute Extraction

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L106"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_get_data_attributes

``` python

def js_get_data_attributes(
    
)->str: # JavaScript function definition

```

*Generate JavaScript function to extract data attributes from element.*

``` python
# Test data attribute extraction
result = js_get_data_attributes()
assert "function getDataAttributes" in result
assert "getAttribute" in result
```

## Modifier Key Detection

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L121"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_get_modifiers

``` python

def js_get_modifiers(
    
)->str: # JavaScript function definition

```

*Generate JavaScript function to extract modifier keys from event.*

``` python
# Test modifier detection
result = js_get_modifiers()
assert "function getModifiers" in result
assert "function modifiersMatch" in result
assert "shiftKey" in result
```

## Combined Utilities

Function to generate all utility functions at once.

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/utils.py#L144"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_all_utils

``` python

def js_all_utils(
    input_selector:str="input, textarea, select, [contenteditable='true']", # input element selector
    default_focus_classes:tuple[str, ...]=('ring-2', 'ring-primary'), # focus ring classes
    scroll_behavior:str='smooth', # scroll behavior
    scroll_block:str='nearest', # scroll block alignment
)->str: # all utility functions combined

```

*Generate all JavaScript utility functions.*

``` python
# Test combined utilities
result = js_all_utils()
assert "isInputFocused" in result
assert "addFocusRing" in result
assert "scrollToElement" in result
assert "updateHiddenInput" in result
assert "triggerClick" in result
assert "getDataAttributes" in result
assert "getModifiers" in result
```
