This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[terra-search-field] Added invalid red box for invalid search field (#…
…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
1 parent
c39f4e2
commit 57bd0a6
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/terra-core-docs/src/terra-dev-site/doc/search-field/example/SearchFieldInvalid.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
15 changes: 15 additions & 0 deletions
15
...erra-core-docs/src/terra-dev-site/doc/search-field/example/SearchFieldInvalid.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |