Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
[terra-search-field] Added invalid red box for invalid search field (#…
Browse files Browse the repository at this point in the history
…3986)

Co-authored-by: UM100080 <UdayKiran.Mattam@cerner.com>
Co-authored-by: SM051274 <sm051274@cerner.net>
Co-authored-by: Supreeth <supreeth.mr1990@gmail.com>
  • Loading branch information
4 people authored Dec 6, 2023
1 parent c39f4e2 commit 57bd0a6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/terra-core-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Unreleased

* Added
* Added aria-label to announce the visual label.
* Added a invalid example in `terra-search-Field`.
* Added aria-label to announce the visual label for `terra-form-select`.

## 1.52.0 - (November 21, 2023)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SearchFieldDisableAutoSearch from './example/SearchFieldDisableAutoSearch
import SearchFieldFilterNumeric from './example/SearchFieldFilterNumeric?dev-site-example';
import SearchFieldFocus from './example/SearchFieldFocus?dev-site-example';
import SearchFieldProgrammaticSet from './example/SearchFieldProgrammaticSet?dev-site-example';
import SearchFieldInvalid from './example/SearchFieldInvalid?dev-site-example';

import SearchFieldPropsTable from 'terra-search-field/lib/SearchField?dev-site-props-table';

Expand Down Expand Up @@ -73,6 +74,7 @@ import SearchField from 'terra-search-field';
<SearchFieldFilterNumeric />
<SearchFieldFocus />
<SearchFieldProgrammaticSet />
<SearchFieldInvalid />

## SearchField Props
<SearchFieldPropsTable />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useState, useRef } from 'react';
import SearchField from 'terra-search-field';
import classNames from 'classnames/bind';
import styles from './SearchFieldInvalid.module.scss';

const cx = classNames.bind(styles);

const SearchFieldInvalid = () => {
const [isInvalid, setInvalid] = useState(false);
const [message, setMessage] = useState('');
const [text, setText] = useState('');
const inputRef = useRef(null);

const handleInvalidSearch = (value) => {
setText(value);
setInvalid(true);
setMessage('INVALID Search Text: ');
if (inputRef.current) {
inputRef.current.classList.add(styles['error-border']); // Add red border on invalid search
}
};

const handleChange = (event, value) => {
setText(value);
setInvalid(false);
};

const handleInput = (event) => {
setText(event.target.value);
};

const handleSearch = (value) => {
setText(value);
setMessage('Search Text: ');
if (inputRef.current) {
inputRef.current.classList.remove(styles['error-border']); // Remove red border on valid search
}
};

return (
<div>
<p>Minimum Search Length is 3</p>
<SearchField
id="searchfield"
inputAttributes={{ 'aria-invalid': isInvalid, 'aria-describedby': 'search-callback-text' }}
onSearch={handleSearch}
onInvalidSearch={handleInvalidSearch}
onChange={handleChange}
onInput={handleInput}
minimumSearchTextLength={3}
value={text}
inputRefCallback={(ref) => { inputRef.current = ref; }}
searchDelay={500}
/>
<div id="search-callback-text" className={isInvalid ? cx('error-text') : ''}>
{message}
{text}
</div>
</div>
);
};

export default SearchFieldInvalid;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
:local {
.error-text {
color: var(--terra-core-docs-error-text-color, #e50000);
font-size: var(--terra-core-docs-error-text-font-size, 0.857rem);
font-weight: var(--terra-core-docs-error-text-font-weight, normal);
line-height: 1.25;
margin-top: var(--terra-core-docs-error-text-margin-top, 0.357em);
outline: 0;
text-align: left;
}

.error-border {
outline: var(--terra-core-docs-error-border-outline, 2px solid #e50000);
}
}

0 comments on commit 57bd0a6

Please sign in to comment.