Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Mouse cursor change for disabled Button #236

Merged
merged 3 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import React, {
import { HtmlButton, HtmlButtonProps } from '../../reset';
import { VisuallyHidden } from '../Visually-hidden/Visually-hidden';
import classnames from 'classnames';
import styled from 'styled-components';
import { disabledCursor } from '../utils/css';

const baseClassName = 'fi-button';
const disabledClassName = `${baseClassName}--disabled`;
Expand Down Expand Up @@ -102,6 +104,14 @@ export class Assertive extends Component<AssertiveProps> {
}
}

const StyledHtmlButton = styled((props: ButtonProps) => (
<HtmlButton {...props} />
))`
&.${disabledClassName} {
${disabledCursor}
}
`;

export class Button extends Component<ButtonProps> {
render() {
const {
Expand All @@ -126,7 +136,7 @@ export class Button extends Component<ButtonProps> {
const onClickProps = !!disabled ? {} : ifMouseNoFocus();
return (
<Fragment>
<HtmlButton
<StyledHtmlButton
{...passProps}
{...onClickProps}
aria-disabled={disabled}
Expand Down
18 changes: 11 additions & 7 deletions src/components/Button/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`calling render with the same component on the same container does not remount 1`] = `
.c0 {
.c1 {
line-height: 1.15;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
Expand All @@ -27,31 +27,35 @@ exports[`calling render with the same component on the same container does not r
cursor: pointer;
}

.c0:-moz-focusring {
.c1:-moz-focusring {
outline: 1px dotted ButtonText;
}

.c0::-moz-focus-inner {
.c1::-moz-focus-inner {
border-style: none;
padding: 0;
}

.c0::-webkit-file-upload-button {
.c1::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit;
}

.c0::-webkit-inner-spin-button {
.c1::-webkit-inner-spin-button {
height: auto;
}

.c0::-webkit-outer-spin-button {
.c1::-webkit-outer-spin-button {
height: auto;
}

.c0.fi-button--disabled {
cursor: not-allowed;
}

<button
aria-disabled="false"
class="fi-button c0"
class="fi-button c0 c1"
data-testid="button"
tabindex="0"
type="button"
Expand Down
5 changes: 5 additions & 0 deletions src/components/utils/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { css } from 'styled-components';

export const disabledCursor = css`
cursor: not-allowed;
`;
6 changes: 5 additions & 1 deletion src/core/Button/Button.baseStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ export const baseStyles = withSuomifiTheme(
&:disabled {
text-shadow: 0 1px 1px ${theme.colors.blackBase};
background: ${theme.gradients.depthBase};
pointer-events: none;
user-select: none;
}

&.fi-button--disabled::after {
border: none;
box-shadow: none;
}

&.fi-button--fullwidth {
display: block;
width: 100%;
Expand Down
24 changes: 16 additions & 8 deletions src/core/Button/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`calling render with the same component on the same container does not remount 1`] = `
.c1 {
.c2 {
line-height: 1.15;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
Expand All @@ -27,28 +27,32 @@ exports[`calling render with the same component on the same container does not r
cursor: pointer;
}

.c1:-moz-focusring {
.c2:-moz-focusring {
outline: 1px dotted ButtonText;
}

.c1::-moz-focus-inner {
.c2::-moz-focus-inner {
border-style: none;
padding: 0;
}

.c1::-webkit-file-upload-button {
.c2::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit;
}

.c1::-webkit-inner-spin-button {
.c2::-webkit-inner-spin-button {
height: auto;
}

.c1::-webkit-outer-spin-button {
.c2::-webkit-outer-spin-button {
height: auto;
}

.c1.fi-button--disabled {
cursor: not-allowed;
}

.c0 {
color: hsl(0,0%,16%);
-webkit-letter-spacing: 0;
Expand Down Expand Up @@ -112,13 +116,17 @@ exports[`calling render with the same component on the same container does not r
.c0:disabled {
text-shadow: 0 1px 1px hsl(0,0%,16%);
background: linear-gradient(0deg,hsl(202,7%,67%) 0%,#c0c5c9 100%);
pointer-events: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.c0.fi-button--disabled::after {
border: none;
box-shadow: none;
}

.c0.fi-button--fullwidth {
display: block;
width: 100%;
Expand Down Expand Up @@ -256,7 +264,7 @@ exports[`calling render with the same component on the same container does not r

<button
aria-disabled="false"
class="fi-button c0 c1"
class="fi-button c0 c1 c2"
data-testid="button"
tabindex="0"
type="button"
Expand Down
26 changes: 15 additions & 11 deletions src/core/Panel/__snapshots__/PanelExpansion.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`calling render with the same component on the same container does not remount 1`] = `
.c4 {
.c5 {
line-height: 1.15;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
Expand All @@ -27,25 +27,25 @@ exports[`calling render with the same component on the same container does not r
cursor: pointer;
}

.c4:-moz-focusring {
.c5:-moz-focusring {
outline: 1px dotted ButtonText;
}

.c4::-moz-focus-inner {
.c5::-moz-focus-inner {
border-style: none;
padding: 0;
}

.c4::-webkit-file-upload-button {
.c5::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit;
}

.c4::-webkit-inner-spin-button {
.c5::-webkit-inner-spin-button {
height: auto;
}

.c4::-webkit-outer-spin-button {
.c5::-webkit-outer-spin-button {
height: auto;
}

Expand Down Expand Up @@ -79,7 +79,11 @@ exports[`calling render with the same component on the same container does not r
max-width: 100%;
}

.c6 {
.c4.fi-button--disabled {
cursor: not-allowed;
}

.c7 {
display: none;
}

Expand All @@ -95,7 +99,7 @@ exports[`calling render with the same component on the same container does not r
cursor: pointer;
}

.c5 {
.c6 {
display: inline-block;
vertical-align: baseline;
}
Expand Down Expand Up @@ -253,15 +257,15 @@ exports[`calling render with the same component on the same container does not r
<button
aria-disabled="false"
aria-expanded="false"
class="fi-button fi-panel-expansion_title fi-panel-expansion_title--no-tag c3 c4"
class="fi-button fi-panel-expansion_title fi-panel-expansion_title--no-tag c3 c4 c5"
data-testid="panel-expansion-title"
tabindex="0"
type="button"
>
Test expansion
<svg
aria-hidden="true"
class="fi-panel-expansion_title-icon c5"
class="fi-panel-expansion_title-icon c6"
focusable="false"
height="1em"
style="fill: hsl(202, 7%, 40%);"
Expand All @@ -275,7 +279,7 @@ exports[`calling render with the same component on the same container does not r
</button>
<div
aria-hidden="true"
class="fi-panel-expansion_content c6 fi-panel c1 c2"
class="fi-panel-expansion_content c7 fi-panel c1 c2"
hidden=""
>
Test expansion content
Expand Down
Loading