-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functionality to clear input from sidenav search and icon gallery search #247
Changes from 1 commit
de40df6
0e20507
eebf794
04b4128
b4980b9
556ab7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
.search { | ||
width: 60%; | ||
padding: 0.75rem 1rem; | ||
margin: 1rem 0; | ||
height: auto; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,37 @@ import cx from 'classnames'; | |
import FeatherIcon from './FeatherIcon'; | ||
import styles from './SearchInput.module.scss'; | ||
|
||
const SearchInput = ({ className, ...props }) => ( | ||
<div className={cx(styles.container, className)}> | ||
<input {...props} className={styles.input} type="text" /> | ||
<FeatherIcon name="search" className={styles.icon} /> | ||
</div> | ||
); | ||
const SearchInput = ({ className, onClear, value, ...props }) => { | ||
const handleClick = (e) => { | ||
e.preventDefault(); | ||
onClear(); | ||
}; | ||
const handleKeyDown = (e) => { | ||
if (e.key === 'Escape') onClear(); | ||
zstix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
return ( | ||
<div className={cx(styles.container, className)}> | ||
<input value={value} {...props} className={styles.input} type="text" /> | ||
<span | ||
role="button" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its typically not a great idea to use a div button for accessibility reasons. We should instead use a That being said, is there a reason you couldn't add the event handlers to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wouldn't trigger when click on the FeatherIcon, I wasn't sure why that was happening which is why I wrapped it in a div. I will change this to a button! |
||
tabIndex={0} | ||
onKeyDown={handleKeyDown} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the intention for this to trigger when the button is focused? |
||
onClick={handleClick} | ||
className={styles.clearButton} | ||
> | ||
<FeatherIcon | ||
name={value !== '' ? 'x' : 'search'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could probably be simplified to |
||
className={styles.icon} | ||
/> | ||
</span> | ||
</div> | ||
); | ||
}; | ||
|
||
SearchInput.propTypes = { | ||
className: PropTypes.string, | ||
onClear: PropTypes.func, | ||
value: PropTypes.string, | ||
}; | ||
|
||
export default SearchInput; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
.icon { | ||
position: absolute; | ||
right: 0.5rem; | ||
bottom: 0.5rem; | ||
stroke: var(--color-neutrals-700); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this comment lost the URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes that comes from my bad habit of clicking ctrl x 😅 I'll fix that