Skip to content

Commit 3ef4231

Browse files
authored
fix: form field validation for variants (#436)
* fix: invalid styling #419 #423 * docs: enabled invalid checkbox stylings
1 parent 37f203b commit 3ef4231

File tree

4 files changed

+36
-43
lines changed

4 files changed

+36
-43
lines changed

source/_patterns/01-elements/_form-elements.scss

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,6 @@
3333
}
3434
}
3535

36-
// Validation
37-
// We need to differentiate here for select elements, that we couldn't handle by :placeholder-shown
38-
// TODO: maybe we could totally restructure this, work with a :not(select) instead, differentiate in between user-invalid and provide a fallback (https://github.com/db-ui/mono/pull/893), etc.
39-
%form-element-validation {
40-
// listing the relevant form attributes related to form validation
41-
&:is(:required, [pattern], [min], [max], [step], [minlength], [maxlength]) {
42-
&,
43-
// workaround for the DB UI Core selectors
44-
&[data-variant] {
45-
&:not([aria-invalid]) {
46-
&:not(:placeholder-shown) {
47-
&:valid {
48-
--formElement---borderColor: #{$db-color-green-600};
49-
}
50-
51-
&:invalid {
52-
--formElement---borderColor: #{$db-color-red-500};
53-
}
54-
}
55-
}
56-
}
57-
}
58-
}
59-
%form-element-validation-programmatic {
60-
&[aria-invalid="true"] {
61-
&,
62-
&[data-variant] {
63-
--formElement---borderColor: #{$db-color-red-500};
64-
}
65-
}
66-
}
67-
6836
// ### Style variations
6937
// Semitransparent
7038
%form-element-semitransparent {
@@ -114,3 +82,25 @@
11482
border-right: $form-elements---borderRight;
11583
border-top: $form-elements---borderTop;
11684
}
85+
86+
// Validation
87+
// We need to differentiate here because of any non-textual input elements like select, radio and checkbox, that we couldn't handle by :placeholder-shown
88+
// TODO: maybe we could totally restructure this, work with a :not(select) instead, differentiate in between user-invalid and provide a fallback (https://github.com/db-ui/mono/pull/893), etc.
89+
%form-element-validation {
90+
&:not([aria-invalid]) {
91+
&:not(:placeholder-shown) {
92+
&:valid {
93+
--formElement---borderColor: #{$db-color-green-600};
94+
}
95+
96+
&:invalid {
97+
--formElement---borderColor: #{$db-color-red-500};
98+
}
99+
}
100+
}
101+
}
102+
%form-element-validation-programmatic {
103+
&[aria-invalid="true"] {
104+
--formElement---borderColor: #{$db-color-red-500};
105+
}
106+
}

source/_patterns/01-elements/checkbox/checkbox.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
id="{{ id }}"{{#if checked}} checked{{/if }}
44
{{#if disabled}} disabled{{/if }}
55
value="{{ value }}"
6-
{{#if describedbyid }} aria-describedby="{{ describedbyid }}"{{/if }}>
6+
{{#if describedbyid }} aria-describedby="{{ describedbyid }}"{{/if }}
7+
{{#if invalid }} aria-invalid="{{ invalid }}"{{/if }}>
78
<label class="elm-label" for="{{ id }}">{{ label }}</label>
89
{{#if indeterminate}}
910
<script>

source/_patterns/01-elements/input/input.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@
107107
color: $db-color-cool-gray-500;
108108
}
109109

110-
/* stylelint-disable order/order */
111-
@extend %form-element-validation;
112-
@extend %form-element-validation-programmatic;
113-
/* stylelint-enable order/order */
114-
115110
// ### Style variations
116111
&[data-variant="semitransparent"] {
117112
@extend %form-element-semitransparent;
@@ -128,6 +123,12 @@
128123
&[data-variant="outline"] {
129124
@extend %form-element-outline;
130125
}
126+
127+
// Validation
128+
/* stylelint-disable order/order */
129+
@extend %form-element-validation;
130+
@extend %form-element-validation-programmatic;
131+
/* stylelint-enable order/order */
131132
}
132133

133134
&[type="search"] {

source/_patterns/01-elements/textarea/textarea.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@
5656
}
5757
}
5858

59-
/* stylelint-disable order/order */
60-
@extend %form-element-validation;
61-
@extend %form-element-validation-programmatic;
62-
/* stylelint-enable order/order */
63-
6459
// TODO: Evaluate whether those could get moved to ../_form-elements.scss
6560
& + output {
6661
// amount of signs output
@@ -94,4 +89,10 @@
9489
&[data-variant="outline"] {
9590
@extend %form-element-outline;
9691
}
92+
93+
// Validation
94+
/* stylelint-disable order/order */
95+
@extend %form-element-validation;
96+
@extend %form-element-validation-programmatic;
97+
/* stylelint-enable order/order */
9798
}

0 commit comments

Comments
 (0)