Skip to content

Commit

Permalink
chore: unify disabled & read-only styling (#974)
Browse files Browse the repository at this point in the history
* add placeholder %is-disabled & replace :disabled and :read-only styles with %is-disabled

* fixes to replace pointer-events:none

* fix menuItem background when disabled
  • Loading branch information
Eevolee authored Mar 3, 2025
1 parent 19c34b6 commit 4afe6c6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 58 deletions.
27 changes: 12 additions & 15 deletions src/components/Dropdown/Dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@

.moonstone-disabled {
& > .moonstone-treeView_item {
@include is-disabled;

pointer-events: none;

&:hover {
pointer-events: none;
}
@extend %is-disabled;
}
}

Expand All @@ -42,13 +36,7 @@
cursor: pointer;

&.moonstone-disabled {
@include is-disabled;

pointer-events: none;

&:hover {
pointer-events: none;
}
@extend %is-disabled;
}

// ---
Expand All @@ -63,6 +51,15 @@
border: var(--border-selector_active);
}

&:focus-visible {
border: var(--border-selector_focus);
outline: none;
}

&:hover:not(.moonstone-disabled) {
color: var(--color-accent);
}

&:not(.moonstone-filled) .moonstone-dropdown_label {
font-style: italic;
color: var(--color-gray_dark60);
Expand All @@ -78,7 +75,7 @@
border: var(--border-selector);
background-color: var(--background-selector);

&:hover {
&:hover:not(.moonstone-disabled) {
border: var(--border-selector_hover);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const Dropdown: React.FC<DropdownProps> = ({
className={clsx('moonstone-dropdown_container', className)}
{...props}
onKeyPress={e => {
if (e.key === 'Enter') {
if (e.key === 'Enter' && !isDisabled) {
handleOpenMenu(e);
}
}}
Expand All @@ -181,7 +181,7 @@ export const Dropdown: React.FC<DropdownProps> = ({
role="dropdown"
className={clsx(cssDropdown)}
tabIndex={0}
onClick={handleOpenMenu}
onClick={!isDisabled && handleOpenMenu}
onKeyPress={(e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
handleSelect(e);
Expand Down
34 changes: 5 additions & 29 deletions src/components/Input/BaseInput/BaseInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,9 @@ $min-width: 40px;

cursor: text;

&:not(:has(input:disabled), :has(input:read-only)) {
&:has(input:hover) {
border: var(--border-selector_hover);
}

&:has(input:focus) {
border: var(--border-selector_focus);
}
}

&:has(input:disabled) {
background-color: var(--color-gray_light40);
&:has(input:disabled),
&:has(input:read-only) {
@extend %is-disabled;
}

&.moonstone-big {
Expand Down Expand Up @@ -80,6 +71,8 @@ $min-width: 40px;
height: calc($default-size - 2px);
margin: 0; // Reset for Safari

color: inherit;

border: 0;
background: none;

Expand Down Expand Up @@ -112,23 +105,6 @@ $min-width: 40px;
}
}

&:read-only {
border: none;
}

&:disabled {
color: var(--color-gray);

border: none;

cursor: default;
opacity: 1; // Reset iOS opacity

~ .moonstone-baseInput_icon {
color: var(--color-gray);
}
}

// Check if the input is empty
&:placeholder-shown {
~ .moonstone-baseInput_icon {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/MenuItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

&.moonstone-disabled,
&.moonstone-disabled:hover {
@include is-disabled;
@extend %is-disabled;

background: none;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Textarea/ControlledTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const ControlledTextarea = React.forwardRef<HTMLTextAreaElement, Controll
placeholder={placeholder}
disabled={isDisabled}
readOnly={isReadOnly}
onChange={onChange}
onBlur={onBlur}
onFocus={onFocus}
onChange={(!isDisabled || !isReadOnly) && onChange}
onBlur={(!isDisabled || !isReadOnly) && onBlur}
onFocus={(!isDisabled || !isReadOnly) && onFocus}
{...props}
/>
);
Expand Down
9 changes: 3 additions & 6 deletions src/components/Textarea/Textarea.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ $minHeight-size: 50px;
}
}

&:disabled {
color: var(--color-gray);

background-color: var(--color-gray_light40);
cursor: default;
opacity: 1; // Reset iOS opacity
&:disabled,
&:read-only {
@extend %is-disabled;
}
}
7 changes: 5 additions & 2 deletions src/utils/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
text-overflow: ellipsis;
}

@mixin is-disabled() {
color: var(--color-gray40);
%is-disabled {
color: var(--color-gray);

background-color: var(--color-gray_light40);

cursor: not-allowed;
opacity: 0.6;
}

0 comments on commit 4afe6c6

Please sign in to comment.