Skip to content

Commit

Permalink
Merge pull request #21581 from Yoast/d-claassen/disable-autocomplete-…
Browse files Browse the repository at this point in the history
…field-desc

Improve disabled state of UI library field components
  • Loading branch information
pls78 committed Sep 3, 2024
2 parents d26269b + a86132e commit 674f65d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { useDescribedBy } from "../../hooks";
* @param {Object} validation The validation state.
* @param {string} [className] Optional CSS class.
* @param {string} label Label.
* @param {Boolean} [disabled] Disabled state.
* @param {JSX.node} [description] Optional description.
* @param {Object} [props] Any extra props.
* @returns {JSX.Element} AutocompleteField component.
*/
const AutocompleteField = forwardRef( ( {
id,
label,
disabled,
description,
validation,
className,
Expand All @@ -25,7 +27,7 @@ const AutocompleteField = forwardRef( ( {
const { ids, describedBy } = useDescribedBy( id, { validation: validation?.message, description } );

return (
<div className={ classNames( "yst-autocomplete-field", className ) }>
<div className={ classNames( "yst-autocomplete-field", disabled && "yst-autocomplete-field--disabled", className ) }>
<Autocomplete
ref={ ref }
id={ id }
Expand All @@ -37,6 +39,7 @@ const AutocompleteField = forwardRef( ( {
validation={ validation }
className="yst-autocomplete-field__select"
buttonProps={ { "aria-describedby": describedBy } }
disabled={ disabled }
{ ...props }
/>
{ validation?.message && (
Expand All @@ -55,6 +58,7 @@ AutocompleteField.displayName = "AutocompleteField";
AutocompleteField.propTypes = {
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
disabled: PropTypes.bool,
description: PropTypes.node,
validation: PropTypes.shape( {
variant: PropTypes.string,
Expand All @@ -63,6 +67,7 @@ AutocompleteField.propTypes = {
className: PropTypes.string,
};
AutocompleteField.defaultProps = {
disabled: false,
description: null,
validation: {},
className: "",
Expand Down
11 changes: 11 additions & 0 deletions packages/ui-library/src/components/autocomplete-field/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
@layer components {
.yst-root {
.yst-autocomplete-field--disabled {
.yst-autocomplete-field__label,
.yst-autocomplete-field__description {
@apply yst-opacity-50;
}

.yst-autocomplete-field__label {
@apply yst-cursor-not-allowed;
}
}

.yst-autocomplete-field__description {
@apply yst-mt-2;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/ui-library/src/components/tag-field/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
.yst-tag-field--disabled {
.yst-tag-field__label,
.yst-tag-field__description {
@apply yst-opacity-50 yst-cursor-not-allowed;
@apply yst-opacity-50;
}

.yst-tag-field__label {
@apply yst-cursor-not-allowed;
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/ui-library/src/components/toggle-field/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
}

.yst-toggle-field__label,
.yst-toggle-field__label-wrapper,
.yst-toggle-field__description {
.yst-toggle-field__label-wrapper {
@apply yst-cursor-not-allowed;
}
}
Expand Down

0 comments on commit 674f65d

Please sign in to comment.