Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

fix(mdButton): focus styles only on keyboard #1594

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/components/button/button-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $button-fab-border-radius: 50% !default;
border-radius: $button-border-radius;

&:not([disabled]) {
&:focus {
&.focus {
background-color: '{{background-500-0.2}}';
}
}
Expand Down Expand Up @@ -34,18 +34,29 @@ $button-fab-border-radius: 50% !default;
color: '{{primary-contrast}}';
}
&:not([disabled]) {
&:focus {
&.focus {
background-color: '{{primary-600}}';
}
}
}
}
&.md-fab {
border-radius: $button-fab-border-radius;
background-color: '{{accent-color}}';
color: '{{accent-contrast}}';
&:not([disabled]) {
&:hover,
&.focus {
background-color: '{{accent-A700}}';
}
}
}

&.md-raised {
color: '{{background-contrast}}';
background-color: '{{background-50}}';
&:not([disabled]) {
&:focus {
&.focus {
background-color: '{{background-200}}';
}
}
Expand All @@ -62,7 +73,7 @@ $button-fab-border-radius: 50% !default;
color: '{{warn-contrast}}';
}
&:not([disabled]) {
&:focus {
&.focus {
background-color: '{{warn-700}}';
}
}
Expand All @@ -79,7 +90,7 @@ $button-fab-border-radius: 50% !default;
color: '{{accent-contrast}}';
}
&:not([disabled]) {
&:focus {
&.focus {
background-color: '{{accent-700}}';
}
}
Expand Down
16 changes: 15 additions & 1 deletion src/components/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ angular.module('material.components.button', [
* </md-button>
* </hljs>
*/
function MdButtonDirective($mdInkRipple, $mdTheming, $mdAria) {
function MdButtonDirective($mdInkRipple, $mdTheming, $mdAria, $timeout) {

return {
restrict: 'EA',
Expand Down Expand Up @@ -95,6 +95,20 @@ function MdButtonDirective($mdInkRipple, $mdTheming, $mdAria) {
element.attr('tabindex', isDisabled ? -1 : 0);
});
}

// restrict focus styles to the keyboard
scope.mouseActive = false;
element
.on('mousedown', function() {
scope.mouseActive = true;
$timeout(function(){
scope.mouseActive = false;
}, 100);
})
.on('focus', function() {
if(scope.mouseActive === false) element.addClass('focus');
})
.on('blur', function() { element.removeClass('focus'); });
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/components/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ $icon-button-margin: 0.600rem !default;
.md-button.md-fab-top-right {
transform: translate3d(0, $button-fab-toast-offset, 0);
&:not([disabled]) {
&:focus,
&.focus,
&:hover {
transform: translate3d(0, $button-fab-toast-offset - 1, 0);
}
Expand All @@ -177,7 +177,7 @@ $icon-button-margin: 0.600rem !default;
.md-button.md-fab-bottom-right {
transform: translate3d(0, -$button-fab-toast-offset, 0);
&:not([disabled]) {
&:focus,
&.focus,
&:hover {
transform: translate3d(0, -$button-fab-toast-offset - 1, 0);
}
Expand Down