@khanacademy/wonder-blocks-dropdown 5.8.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,7 +68,7 @@ export declare function useListbox({ children: options, disabled, disableSpaceSe
68
68
  rightAccessory?: React.ReactNode;
69
69
  subtitle1?: import("@khanacademy/wonder-blocks-cell").TypographyText | undefined;
70
70
  subtitle2?: import("@khanacademy/wonder-blocks-cell").TypographyText | undefined;
71
- }, keyof import("@khanacademy/wonder-blocks-core").AriaAttributes | "label" | "style" | "leftAccessory" | "rightAccessory" | "testId" | "onClick" | "subtitle1" | "id" | "subtitle2" | "value" | "labelAsText" | "variant" | "parentComponent"> & {
71
+ }, keyof import("@khanacademy/wonder-blocks-core").AriaAttributes | "style" | "label" | "leftAccessory" | "rightAccessory" | "testId" | "onClick" | "subtitle1" | "subtitle2" | "value" | "id" | "labelAsText" | "variant" | "parentComponent"> & {
72
72
  selected?: boolean | undefined;
73
73
  role?: "menuitem" | "menuitemcheckbox" | "option" | undefined;
74
74
  disabled?: boolean | undefined;
@@ -0,0 +1,39 @@
1
+ type SingleSelectedValue = string | null | undefined;
2
+ type MultiSelectedValues = string[];
3
+ export type SelectValue = SingleSelectedValue | MultiSelectedValues;
4
+ export type SelectValidationProps<T extends SelectValue> = {
5
+ value?: T;
6
+ disabled?: boolean;
7
+ validate?: (value: T) => string | null | void;
8
+ onValidate?: (errorMessage?: string | null | undefined) => unknown;
9
+ required?: boolean | string;
10
+ open?: boolean;
11
+ };
12
+ /**
13
+ * Hook for validation logic for select based fields. Based on the props provided,
14
+ * the hook will:
15
+ * - call the `validate` and `onValidate` props on initialization and mount
16
+ * - provide validation functions for specific events
17
+ * - these functions will call the `validate` and `onValidate` props as needed
18
+ *
19
+ * @returns {object} An object with:
20
+ * - `errorMessage` - The error message from validation.
21
+ * - `onOpenerBlurValidation` - Validation logic for when the opener is blurred
22
+ * - `onDropdownClosedValidation` - Validation logic for when the opener is
23
+ * closed
24
+ * - `onSelectionValidation` - Validation logic for when a user is done
25
+ * selecting (a) value/value(s)
26
+ * - `onSelectedValuesChangeValidation` - Validation logic for when selected
27
+ * values are updated before selection is done (ie. values are updated and
28
+ * dropdown isn't closed yet). Note that this should only be called when there
29
+ * are multiple values that can be selected. onSelectionValidation should be
30
+ * used whenever the user is done selecting a value or values.
31
+ */
32
+ export declare function useSelectValidation<T extends SelectValue>({ value, disabled, validate, onValidate, required, open, }: SelectValidationProps<T>): {
33
+ errorMessage: string | null;
34
+ onOpenerBlurValidation: () => void;
35
+ onDropdownClosedValidation: () => void;
36
+ onSelectionValidation: (newValue: T) => void;
37
+ onSelectedValuesChangeValidation: () => void;
38
+ };
39
+ export {};