Skip to content

Commit 8c60000

Browse files
author
Catherine Ligad
authored
Add isInvalid field to tagInput (#1398)
* add isInvalid field to tagInput * revert removal of styles * add isInvalid to ts interface * feedback -- change style addition
1 parent 2f73d2d commit 8c60000

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,7 @@ export interface TagInputOwnProps {
24992499
addOnBlur?: boolean
25002500
className?: string
25012501
disabled?: boolean
2502+
isInvalid?: boolean
25022503
height?: number
25032504
inputProps?: PolymorphicBoxProps<'input', TextOwnProps>
25042505
inputRef?: React.Ref<HTMLInputElement>

src/tag-input/src/TagInput.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const internalStyles = {
2828

2929
const pseudoSelectors = {
3030
_focused: '&[aria-activedescendant]',
31-
_disabled: '&[aria-disabled="true"]'
31+
_disabled: '&[aria-disabled="true"]',
32+
_invalid: '&[aria-invalid="true"]:not(:focus)'
3233
}
3334

3435
const TagInput = memo(
@@ -50,6 +51,7 @@ const TagInput = memo(
5051
className,
5152
inputProps = emptyProps,
5253
inputRef,
54+
isInvalid,
5355
...rest
5456
} = props
5557
const [inputValue, setInputValue] = useState('')
@@ -165,6 +167,7 @@ const TagInput = memo(
165167
<Box
166168
aria-disabled={disabled || undefined}
167169
aria-activedescendant={isFocused ? id : undefined}
170+
aria-invalid={isInvalid}
168171
className={cx(themedContainerClassName, className)}
169172
ref={ref}
170173
onBlur={handleBlur}
@@ -199,6 +202,8 @@ TagInput.propTypes = {
199202
className: PropTypes.string,
200203
/** Whether or not the input should be disabled. */
201204
disabled: PropTypes.bool,
205+
/** Whether or not the input is invalid. */
206+
isInvalid: PropTypes.bool,
202207
/** The vertical size of the input */
203208
height: PropTypes.number,
204209
/** Props to pass to the input component. Note that `ref` and `key` are not supported. See `inputRef`. */

src/tag-input/stories/TagInput.stories.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ storiesOf('tag-input', module).add('TagInput', () => (
122122
)}
123123
</StateManager>
124124
</StorySection>
125+
<StorySection>
126+
<StoryHeader>
127+
<StoryHeading>Invalid</StoryHeading>
128+
</StoryHeader>
129+
<StateManager>
130+
{({ addValues, removeValue, values }) => (
131+
<TagInput
132+
inputProps={{ placeholder: 'Enter something...', validationMessage: 'This field should not be empty' }}
133+
values={values}
134+
onAdd={addValues}
135+
onRemove={removeValue}
136+
isInvalid={true}
137+
/>
138+
)}
139+
</StateManager>
140+
</StorySection>
125141
<StorySection>
126142
<StoryHeader>
127143
<StoryHeading>With `tagProps`</StoryHeading>

src/themes/default/components/tag-input.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const appearances = {
1717
_disabled: {
1818
cursor: 'not-allowed',
1919
backgroundColor: 'colors.gray100'
20+
},
21+
_invalid: {
22+
borderColor: 'colors.red600'
2023
}
2124
}
2225
}

0 commit comments

Comments
 (0)