Skip to content

Commit

Permalink
Better accessibility for boolean and select widgets ("replaced checkb…
Browse files Browse the repository at this point in the history
…ox" and selectize)
  • Loading branch information
bago committed May 30, 2022
1 parent 728ce19 commit bc2ec39
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 14 deletions.
35 changes: 33 additions & 2 deletions src/css/app_standalone_material.less
Expand Up @@ -40,6 +40,11 @@
text-transform: uppercase;
}

.button-style-focus() {
background-color: lighten(@button-background-color, 10%);
box-shadow: none;
}

#main-edit-area .tool {
border-radius: 100%;
padding: 4px;
Expand All @@ -48,15 +53,22 @@
}

#toolbar, #preview-toolbar {
.ui-buttonset {
&:focus-within {
background-color: @mosaico-ui-background-color;
box-shadow: none;
}
}
.ui-button {
border-radius: 0;
padding-top: 7px;
padding-bottom: 7px;
line-height: 22px;

background-color: @mosaico-ui-background-color;
&:hover, &.pressed {
&:hover, &.pressed, &:focus, &.ui-state-focus {
background-color: lighten(@mosaico-ui-background-color, 10%);
box-shadow: none;
}
&.selected, &.ui-state-active {
border-bottom: 2px solid @button-text-color;
Expand Down Expand Up @@ -86,6 +98,12 @@
li {
margin: 1px 1px 0 0;
line-height: @topbar-height - 4px;

&.ui-state-focus {
background-color: lighten(@mosaico-ui-background-color, 10%);
box-shadow: none;
}

a {
border-radius: 0;
}
Expand All @@ -97,7 +115,7 @@
box-shadow: 1px 1px 3px @shadow-color;
}

.tabs-style(@activeclass: ~'.active', @buttonstyle: false) {
.tabs-style(@activeclass: ~'.active', @buttonstyle: false, @focusclass: ~'.focus') {

text-transform: uppercase;

Expand All @@ -114,13 +132,22 @@
}
}

li@{focusclass} when (@buttonstyle) {
.button-style-focus();
}
li@{focusclass} when not (@buttonstyle) {
.input-style-focus();
}

li@{activeclass} a {
& when(@buttonstyle) {
background-color: transparent;
color: @button-text-color;
border-bottom: 3px solid @button-text-color;
}
}


}

#main-toolbox {
Expand Down Expand Up @@ -153,6 +180,10 @@


.objEdit .propInput input[type=checkbox] {
&:focus + .checkbox-replacer:after {
.input-style-focus;
}

&:checked + .checkbox-replacer:before {
margin-left: 20px;
background-color: @button-background-color;
Expand Down
16 changes: 14 additions & 2 deletions src/css/style_elements_jquery.less
Expand Up @@ -29,6 +29,10 @@

.ui-button {
.button-style();

&.ui-state-focus {
.button-style-focus();
}

.ui-button-text, .ui-icon {
color: @button-text-color;
Expand All @@ -50,6 +54,14 @@

.ui-buttonset {
.buttonset-style();
&:focus-within {
.button-style-focus();

.ui-button {
// reset .button-style-focus();
.button-unstyle-focus();
}
}
}

.ui-dialog {
Expand Down Expand Up @@ -203,7 +215,7 @@
*/
.ui-tabs.tabs_horizontal {
> ul {
.tabs-style(~'.ui-state-active', false);
.tabs-style(~'.ui-state-active', false, ~'.ui-state-focus');
padding: 0px 0px 0px .5em;
}
.ui-tabs-panel {
Expand All @@ -215,7 +227,7 @@
}
.ui-tabs.tabs_horizontal.button_color {
> ul {
.tabs-style(~'.ui-state-active', true);
.tabs-style(~'.ui-state-active', true, ~'.ui-state-focus');
}
}

Expand Down
38 changes: 33 additions & 5 deletions src/css/style_elements_mixins.less
Expand Up @@ -22,6 +22,22 @@
vertical-align: middle;
}

.input-style-focus() {
border-color: @input-focus-border-color;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px fade(@input-focus-border-color, 60);
outline: 0 none;
}

.button-style-focus() {
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px fade(@input-focus-border-color, 60);
outline: 0 none;
}

.button-unstyle-focus() {
box-shadow: none;
outline: 0 none;
}

.button-style() {
.input-button-common();
display: inline-block;
Expand Down Expand Up @@ -105,6 +121,9 @@
content: '...';
}*/
}
&:focus {
.button-style-focus;
}
}

.buttonset-style() {
Expand Down Expand Up @@ -144,9 +163,7 @@
transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;

&:focus {
border-color: @input-focus-border-color;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px fade(@input-focus-border-color, 60);
outline: 0 none;
.input-style-focus;
}
&.inline {
margin-right: .5em;
Expand Down Expand Up @@ -346,7 +363,7 @@
}
}

.tabs-style(@activeclass: ~'.active', @buttonstyle: false) {
.tabs-style(@activeclass: ~'.active', @buttonstyle: false, @focusclass: ~'.focus') {
& when (@buttonstyle) {
background-color: @sidebar-background-color;
}
Expand Down Expand Up @@ -382,6 +399,18 @@
outline: 0 none !important;
}
}
li@{focusclass} when (@buttonstyle) {
outline: none;
a {
.button-style-focus();
}
}
li@{focusclass} when not (@buttonstyle) {
outline: none;
a {
.input-style-focus();
}
}
li@{activeclass} a {
border-bottom: @tabs-border-width solid @background-color;
background: transparent;
Expand All @@ -395,7 +424,6 @@
color: @text-color;
}
}

}


Expand Down
5 changes: 5 additions & 0 deletions src/css/style_elements_selectize.less
Expand Up @@ -46,7 +46,12 @@

pointer-events:none;
}

&.focus {
.input-style-focus();
}
}

.selectize-input.dropdown-active::before {
// prevent the 1px move
display: none;
Expand Down
16 changes: 15 additions & 1 deletion src/css/style_mosaico_tools.less
Expand Up @@ -450,7 +450,15 @@
}

.objEdit input[type=checkbox] {
display: none;
// make the replacement accessible
// display: none;
opacity: 0;
position: absolute;
z-index: -1000;

&:focus + .checkbox-replacer:before {
.button-style-focus;
}

& + .checkbox-replacer {
width: 1.28571429em;
Expand Down Expand Up @@ -893,6 +901,12 @@
z-index: 1;
}

&:not(:checked):focus + .checkbox-replacer:after,
&:checked:focus + .checkbox-replacer:before {
.button-style-focus;
}


}

/* while local-editing we always show the local editor */
Expand Down
4 changes: 2 additions & 2 deletions src/js/converter/editor.js
Expand Up @@ -43,7 +43,7 @@ var _propInput = function(model, prop, propAccessor, editType, widgets) {
onfocusbinding += ', event: { focus: function(ui, event) { $($element).click(); } } ';
}

html += '<label class="data-' + widget + '"' + (widget == 'boolean' ? ' data-bind="event: { mousedown: function(ui, evt) { if (evt.button == 0) { var input = $($element).find(\'input\'); var ch = input.prop(\'checked\'); setTimeout(function() { input.click(); input.prop(\'checked\', !ch); input.trigger(\'change\'); }, 0); } } }, click: function(ui, evt) { evt.preventDefault(); }, clickBubble: false"' : '') + '>';
html += '<div class="data-' + widget + '">';

if (typeof widgets !== 'undefined' && typeof widgets[widget] !== 'undefined') {
var w = widgets[widget];
Expand All @@ -57,7 +57,7 @@ var _propInput = function(model, prop, propAccessor, editType, widgets) {
html += '<input size="7" type="text" value="nothing" data-bind="value: ' + propAccessor + ', ' + onfocusbinding + '" />';
}

html += '</label>';
html += '</div>';

return html;
};
Expand Down
7 changes: 5 additions & 2 deletions src/js/widgets/boolean.js
Expand Up @@ -6,8 +6,11 @@ var widgetPlugin = {
return {
widget: 'boolean',
html: function(propAccessor, onfocusbinding, parameters) {
return '<input type="checkbox" value="nothing" data-bind="checked: ' + propAccessor + ', ' + onfocusbinding + '" />' +
'<span class="checkbox-replacer" ></span>';
var html = '<!-- ko letproxy: { prop: ' + propAccessor + ' } -->';
html += '<input type="checkbox" data-bind="checked: prop" />';
html += '<span class="checkbox-replacer" data-bind="event: { mousedown: function(ui, evt) { prop(!prop()); } }, click: function(ui, evt) { evt.preventDefault(); }, clickBubble: false" ></span>';
html += '<!-- /ko -->';
return html;
}
};
},
Expand Down

0 comments on commit bc2ec39

Please sign in to comment.