# All files / form useListboxProvider.ts

0% Statements 0/43
0% Branches 0/1
0% Functions 0/1
0% Lines 0/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44

     "use client";
    import { createContext, useContext, type RefObject } from "react";

    /**
     * @internal
     * \@remarks \@since 6.0.0
     */
    export interface ListboxContext {
      /**
       * This ref is used to trigger the change event when an option is clicked.
       */
      inputRef: RefObject<HTMLInputElement>;

      /**
       * This is used within the `Option` component to determine if it is currently
       * selected or not.
       */
      currentValue: string | number | null;

      disableSelectedIcon: boolean;
    }

    const context = createContext<ListboxContext>({
      inputRef: { current: null },
      currentValue: null,
      disableSelectedIcon: false,
    });

    /**
     * **Client Component**
     *
     * @internal
     * @remarks \@since 6.0.0
     */
    export const { Provider: ListboxProvider } = context;

    /**
     * @internal
     * @remarks \@since 6.0.0
     */
    export function useListboxContext(): ListboxContext {
      return useContext(context);
    }