Skip to content
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

fix(Search): add disabled prop #6916

22 changes: 18 additions & 4 deletions packages/components/src/components/search/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@
}
}

.#{$prefix}--search-input[disabled] ~ .#{$prefix}--search-magnifier {
fill: $disabled;
}

.#{$prefix}--search--light .#{$prefix}--search-input {
background: $field-02;
}
Expand Down Expand Up @@ -213,6 +209,24 @@
}
}

.#{$prefix}--search--disabled .#{$prefix}--search-close {
outline: none;
cursor: not-allowed;

&:hover {
background-color: transparent;
border-bottom-color: transparent;
}

&:hover::before {
background-color: transparent;
}
}

.#{$prefix}--search--disabled svg {
fill: $disabled;
}

.#{$prefix}--search-close:focus,
.#{$prefix}--search-close:active {
&::before {
Expand Down
3 changes: 3 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4370,6 +4370,9 @@ Map {
],
"type": "oneOfType",
},
"disabled": Object {
"type": "bool",
},
"id": Object {
"type": "string",
},
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Search/Search-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const props = () => ({
className: 'some-class',
size: select('Size (size)', sizes, 'xl'),
light: boolean('Light variant (light)', false),
disabled: boolean('Disabled (disabled)', false),
name: text('Form item name (name)', ''),
defaultValue: text('Default value (defaultValue)', ''),
labelText: text('Label text (labelText)', 'Search'),
Expand Down
9 changes: 9 additions & 0 deletions packages/react/src/components/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export default class Search extends Component {
*/
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

/**
* Specify whether the `<input>` should be disabled
*/
disabled: PropTypes.bool,

/**
* Specify a custom `id` for the input
*/
Expand Down Expand Up @@ -145,6 +150,7 @@ export default class Search extends Component {
small,
size = !small ? 'xl' : 'sm',
light,
disabled,
...other
} = this.props;

Expand All @@ -154,6 +160,7 @@ export default class Search extends Component {
[`${prefix}--search`]: true,
[`${prefix}--search--${size}`]: size,
[`${prefix}--search--light`]: light,
[`${prefix}--search--disabled`]: disabled,
[className]: className,
});

Expand All @@ -175,6 +182,7 @@ export default class Search extends Component {
autoComplete="off"
{...other}
type={type}
disabled={disabled}
className={`${prefix}--search-input`}
id={id}
placeholder={placeHolderText}
Expand All @@ -185,6 +193,7 @@ export default class Search extends Component {
/>
<button
className={clearClasses}
disabled={disabled}
onClick={this.clearInput}
type="button"
aria-label={closeButtonLabelText}>
Expand Down