Skip to content

Commit

Permalink
saving validation picker
Browse files Browse the repository at this point in the history
  • Loading branch information
eunicekokor committed Apr 26, 2023
1 parent 1028284 commit 2368562
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import theme from '../theme';
import { useProviderProps } from '../provider';
import { Field } from '../field';
import { dimensionValue } from '../utils/styleProps';
import { AlertCircleOutline, Icon } from '../icon';

function Picker<T extends object>(
props: PickerProps<T>,
Expand All @@ -47,6 +48,7 @@ function Picker<T extends object>(
autoFocus,
addonBefore,
menuWidth,
validationState,
} = props;

let state = useSelectState(props);
Expand Down Expand Up @@ -154,6 +156,16 @@ function Picker<T extends object>(
minWidth: isQuiet ? '200px' : buttonWidth,
};

let isInvalid = validationState === 'invalid';

const validation = (
<Icon
key="validation-icon"
className={`ac-dropdown__validation-icon ac-dropdown__validation-icon--${validationState}`}
svg={<AlertCircleOutline />}
/>
);

const overlay = (
<Popover
isOpen={state.isOpen}
Expand Down Expand Up @@ -193,6 +205,8 @@ function Picker<T extends object>(
{
'is-disabled': isDisabled,
'ac-dropdown--quiet': isQuiet,
'ac-dropdown--invalid': isInvalid,
'ac-dropdown--valid': validationState === 'valid',
},
props.className
)}
Expand Down Expand Up @@ -229,6 +243,9 @@ function Picker<T extends object>(
>
<div>{contents}</div>
{isLoadingInitial && 'Loading...'}
{validationState && validationState === 'invalid' && !isLoadingInitial
? validation
: null}
</DropdownButton>
</PressResponder>
{state.collection.size === 0 ? null : overlay}
Expand Down
7 changes: 5 additions & 2 deletions src/types/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SingleSelection } from './selection';
import { FocusableProps } from './events';
import { StyleProps } from './style';
import { DimensionValue } from './core';
import { Validation, AriaValidationProps } from '../types';

export interface SelectProps<T>
extends CollectionBase<T>,
Expand All @@ -31,7 +32,8 @@ export interface AriaSelectProps<T>
extends SelectProps<T>,
DOMProps,
AriaLabelingProps,
FocusableDOMProps {
FocusableDOMProps,
AriaValidationProps {
/**
* Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).
*/
Expand All @@ -45,7 +47,8 @@ export interface AriaSelectProps<T>
export interface PickerProps<T>
extends AriaSelectProps<T>,
AddonableProps,
StyleProps {
StyleProps,
Validation {
/**
* Whether the picker should be displayed with a quiet style.
* @default false
Expand Down

0 comments on commit 2368562

Please sign in to comment.