Skip to content

Commit ddb7574

Browse files
committed
[FIX] web: checkboxes design & consistency
The main objective of this commit is to make checkboxes consistent and fix their spacing issues. Prior to these changes, the checkboxes on the `product_view` were too close to their neighboring option labels, making it difficult to know which checkbox to tick. The new changes fixes inconsistencies in general such as undesired hovering effects and the cursor behaviors on disabled inputs. This commit also removes the margin in the checkbox template since the padding from the checkbox wrapper compensates for the spacing between the checkboxes and their respective labels. Tweaking the selector in `settings_form_view.scss` to ignore boolean field inputs allows us to get rid of max-width and margin overrides introduced in commit b90059e. Most checkboxes were already falling under their labels on mobile, but this change impacted those that were not. To address this issue, we decided to consistently change the position of the checkboxes left to their labels for small devices in form view. This required slight adjustments to the `form_group.xml` template. Still in form_view, for some of the specific checkboxes such as `o_checkbox_optional_field` the changes in `form_controller.scss` are made to mimic the new behavior for mobile sized screen. However, if they are using the form_group template, their behavior is unchanged at the moment. Finally, even if these changes makes it better for most of them, some checkboxes in `settings` still require some minor adjustments and will be addressed in task-3113372. task-3094083 closes odoo#107520 Related: odoo/enterprise#37773 Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com>
1 parent f47b306 commit ddb7574

File tree

7 files changed

+45
-35
lines changed

7 files changed

+45
-35
lines changed

addons/product/views/product_views.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@
4848
</div>
4949
</h1>
5050
</div>
51-
<style>
52-
div[name="options"] .o_field_boolean > div {
53-
margin-left: 10px;
54-
margin-right: 0px;
55-
}
56-
</style>
5751
<div name="options">
5852
<span class="d-inline-block">
5953
<field name="sale_ok"/>

addons/web/static/src/legacy/scss/utils.scss

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,12 @@
147147

148148
@mixin o-field-pointer() {
149149
// Force `pointer`cursor on inputs and labels
150-
&:not(:disabled):not(.disabled) {
151-
&, input, label {
152-
cursor: pointer;
153-
}
150+
.form-check-input:not(:disabled), .form-check-input:not(:disabled) + label {
151+
cursor: pointer;
152+
}
154153

155-
&:hover, &:hover .form-check-input {
156-
border-color: $form-check-input-checked-border-color;
157-
}
154+
&:hover, &:hover .form-check-input:not(:disabled) {
155+
border-color: $form-check-input-checked-border-color;
158156
}
159157
}
160158

addons/web/static/src/views/fields/boolean/boolean_field.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<templates xml:space="preserve">
33

44
<t t-name="web.BooleanField" owl="1">
5-
<CheckBox id="props.id" value="props.value or false" className="'d-inline-block me-2'" disabled="isReadonly" onChange.bind="onChange" />
5+
<CheckBox id="props.id" value="props.value or false" className="'d-inline-block'" disabled="isReadonly" onChange.bind="onChange" />
66
</t>
77

88
</templates>

addons/web/static/src/views/form/form_controller.scss

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@
4242
}
4343

4444
.o_field_widget {
45-
width: 100%;
4645
margin-bottom: $o-form-spacing-unit * 2;
4746

47+
&:not(.o_field_boolean){
48+
width: 100%;
49+
}
50+
4851
> .o_field_widget {
4952
margin-bottom: 0;
5053
}
@@ -487,9 +490,14 @@
487490
.o_checkbox_optional_field {
488491
display: flex;
489492

490-
@include media-breakpoint-down(md) {
493+
@include media-breakpoint-down(sm) {
491494
flex-wrap: wrap;
492-
justify-content: space-between;
495+
.o_field_boolean {
496+
order: -1;
497+
}
498+
.o_field_boolean + div {
499+
width: 100%;
500+
}
493501
}
494502

495503
> .o_form_label {
@@ -863,11 +871,9 @@
863871
}
864872
}
865873

866-
// Boolean
867-
.o_field_boolean {
868-
margin-right: $o-form-spacing-unit;
869-
max-width: 40px !important;
870-
padding-right: 0 !important;
874+
// Boolean
875+
.o_field_boolean + .o_form_label {
876+
margin-right: $o-form-spacing-unit * 3;
871877
}
872878

873879
// Timezone widget warning

addons/web/static/src/views/form/form_group/form_group.xml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,27 @@
3939
</t>
4040

4141
<t t-name="web.Form.InnerGroup.ItemComponent" owl="1">
42-
<div class="o_cell o_wrap_label flex-grow-1 flex-sm-grow-0 w-100 text-break text-900">
43-
<t t-component="cell.Component" t-if="cell.isVisible" t-props="cell.props"/>
44-
</div>
45-
<div
42+
<t t-if="cell.props.fieldInfo.FieldComponent.name !== 'BooleanField'">
43+
<div class="o_cell o_wrap_label flex-grow-1 flex-sm-grow-0 w-100 text-break text-900">
44+
<t t-component="cell.Component" t-if="cell.isVisible" t-props="cell.props"/>
45+
</div>
46+
<div
4647
class="o_cell o_wrap_input flex-grow-1 flex-sm-grow-0"
47-
t-attf-style="{{ cell.itemSpan -1 > 1 ? 'grid-column: span ' + (cell.itemSpan -1) + ';' : '' }}{{ cell.width ? 'width: ' + cell.width + '%' + ';' : '' }}"
48-
>
49-
<t t-slot="{{ cell.name }}" />
50-
</div>
48+
t-attf-style="{{ cell.itemSpan -1 > 1 ? 'grid-column: span ' + (cell.itemSpan -1) + ';' : '' }}{{ cell.width ? 'width: ' + cell.width + '%' + ';' : '' }}">
49+
<t t-slot="{{ cell.name }}"/>
50+
</div>
51+
</t>
52+
<t t-else="">
53+
<div class="o_wrap_field_boolean d-flex flex-wrap d-sm-contents flex-sm-nowrap">
54+
<div class="o_cell o_wrap_label flex-sm-grow-0 text-break text-900">
55+
<t t-component="cell.Component" t-if="cell.isVisible" t-props="cell.props"/>
56+
</div>
57+
<div class="o_cell o_wrap_input order-first flex-sm-grow-0 order-sm-0"
58+
t-attf-style="{{ cell.itemSpan -1 > 1 ? 'grid-column: span ' + (cell.itemSpan -1) + ';' : '' }}">
59+
<t t-slot="{{ cell.name }}" />
60+
</div>
61+
</div>
62+
</t>
5163
</t>
5264

5365
</templates>

addons/web/static/src/webclient/settings_form_view/settings_form_view.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
width: 100%;
3232
}
3333

34-
.o_field_widget {
34+
.o_field_widget:not(.o_field_boolean) {
3535
@include media-breakpoint-up(md) {
3636
width: 50%;
3737
}

addons/web/static/tests/views/form/form_view_tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8548,7 +8548,7 @@ QUnit.module("Views", (hooks) => {
85488548
// Verify .field_group content
85498549
var $fieldGroupRows = $fieldGroup.find("> .o_wrap_field");
85508550
assert.strictEqual($fieldGroupRows.length, 5, "there should be 5 rows in .o_wrap_field");
8551-
var $fieldGroupFirstRowTds = $fieldGroupRows.eq(0).children(".o_cell");
8551+
var $fieldGroupFirstRowTds = $fieldGroupRows.eq(0).find(".o_cell");
85528552
assert.strictEqual(
85538553
$fieldGroupFirstRowTds.length,
85548554
2,
@@ -8580,7 +8580,7 @@ QUnit.module("Views", (hooks) => {
85808580
"width: 33",
85818581
"second cell colspan should be default one (no style) and be 33.3333%"
85828582
);
8583-
var $fieldGroupThirdRowTds = $fieldGroupRows.eq(2).children(".o_cell"); // new row as label/field pair colspan is greater than remaining space
8583+
var $fieldGroupThirdRowTds = $fieldGroupRows.eq(2).find(".o_cell"); // new row as label/field pair colspan is greater than remaining space
85848584
assert.strictEqual(
85858585
$fieldGroupThirdRowTds.length,
85868586
2,
@@ -8607,7 +8607,7 @@ QUnit.module("Views", (hooks) => {
86078607
"grid-column: span 3;width: 100",
86088608
"the cell should have a colspan equal to 3 and have 100% width"
86098609
);
8610-
var $fieldGroupFifthRowTds = $fieldGroupRows.eq(4).children(".o_cell"); // label/field pair can be put after the 1-colspan span
8610+
var $fieldGroupFifthRowTds = $fieldGroupRows.eq(4).find(".o_cell"); // label/field pair can be put after the 1-colspan span
86118611
assert.strictEqual(
86128612
$fieldGroupFifthRowTds.length,
86138613
3,
@@ -8796,7 +8796,7 @@ QUnit.module("Views", (hooks) => {
87968796
);
87978797
assert.containsN(
87988798
target,
8799-
".main_inner_group > .o_wrap_field:last > .o_wrap_label",
8799+
".main_inner_group > .o_wrap_field:last .o_wrap_label",
88008800
2,
88018801
"there should be two labels in the second row"
88028802
);

0 commit comments

Comments
 (0)