Skip to content

Commit

Permalink
improve form validation styles
Browse files Browse the repository at this point in the history
  • Loading branch information
basher committed Aug 21, 2024
1 parent ce8549a commit dcf9844
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 10 additions & 4 deletions ui/src/css/form/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,24 @@ Dependencies.
}
}

&:has(:invalid:required:focus) {
&:has(:user-invalid:required) {
@include validation;
}
}

// Errors rendered directly in HTML, or via JavaScript.
&__error {
color: $color-error;
}

&__field--has-error {
@include validation;
}

&__error {
color: $color-error;
&:has(:valid) {
.form__error {
display: none;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/src/css/mixins/_focus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Dependencies.

&:hover {
@if $background {
&:not(:disabled, :invalid, :valid) {
&:not(:disabled) {
background-color: hsl(var(--color-brand) / 10%);
}
}
Expand Down
4 changes: 3 additions & 1 deletion ui/src/css/mixins/_form-field-reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ Dependencies.
border-width: $border-width-m;
}

&:invalid:required:focus {
&:user-invalid:required {
background-color: hsl(var(--color-accent-negative) / 10%);
border-color: $color-error;
border-width: $border-width-m;
}

// ARIA.
&[aria-invalid='true'] {
background-color: hsl(var(--color-accent-negative) / 10%);
border-color: $color-error;
border-width: $border-width-m;
}
}

0 comments on commit dcf9844

Please sign in to comment.