Skip to content

Commit

Permalink
fix: Center align the search icon in the search input
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 30, 2020
1 parent 4fcbb79 commit f490c89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/components/FeatherIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import PropTypes from 'prop-types';
import cx from 'classnames';
import styles from './FeatherIcon.module.scss';

const FeatherIcon = ({ className, name, size = '1em' }) => {
const FeatherIcon = ({ className, name, size = '1em', ...props }) => {
const paths = ICONS[name];

return paths ? (
<svg
{...props}
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
className={cx(styles.icon, className)}
Expand Down
10 changes: 8 additions & 2 deletions src/components/SearchInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ const SearchInput = ({ className, onClear, value, ...props }) => {
<div className={styles.buttonContainer}>
<button
onClick={handleClick}
className={styles.button}
className={cx(styles.button, {
[styles.clearButton]: Boolean(value),
})}
onKeyDown={(e) => e.preventDefault()}
type="button"
>
<FeatherIcon name={value ? 'x' : 'search'} className={styles.icon} />
<FeatherIcon
name={value ? 'x' : 'search'}
className={styles.icon}
onClick={handleClick}
/>
</button>
</div>
</div>
Expand Down
14 changes: 11 additions & 3 deletions src/components/SearchInput.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}

.icon {
display: block;
stroke: var(--color-neutrals-700);
}

Expand All @@ -16,15 +17,22 @@
padding-right: calc(1rem + 1em);
}

.button[type='button'] {
.button {
display: block;
background-color: transparent;
border: none;
margin: 0;
padding: 0.25rem;
padding: 0;
outline: none;
}

.clearButton {
&:hover {
cursor: pointer;
}
}

.buttonContainer {
position: absolute;
right: 0.5rem;
bottom: 0.25rem;
}

0 comments on commit f490c89

Please sign in to comment.