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

Improving EuiImage accessibility #2447

Merged
merged 9 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Improved a11y in `EuiImage` ([#2447](https://github.com/elastic/eui/pull/2447))
- Added ability for `EuiColorStops` to accept user-defined range bounds ([#2396](https://github.com/elastic/eui/pull/2396))

## [`14.6.0`](https://github.com/elastic/eui/tree/v14.6.0)
Expand Down
18 changes: 11 additions & 7 deletions src/components/image/__snapshots__/image.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`EuiImage is rendered 1`] = `
aria-label="aria-label"
class="euiImage euiImage--large testClass1 testClass2"
data-test-subj="test subject string"
role="figure"
>
<img
alt="alt"
Expand All @@ -15,13 +16,16 @@ exports[`EuiImage is rendered 1`] = `
`;

exports[`EuiImage is rendered and allows full screen 1`] = `
<button
<figure
aria-label="aria-label"
class="euiImage euiImage--large euiImage--allowFullScreen testClass1 testClass2"
type="button"
data-test-subj="test subject string"
role="figure"
>
<figure
aria-label="aria-label"
data-test-subj="test subject string"
<button
aria-label="Open image full screen"
class="euiImage__button"
type="button"
>
<img
alt="alt"
Expand All @@ -36,6 +40,6 @@ exports[`EuiImage is rendered and allows full screen 1`] = `
width="16"
xmlns="http://www.w3.org/2000/svg"
/>
</figure>
</button>
</button>
</figure>
`;
67 changes: 30 additions & 37 deletions src/components/image/_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,35 @@
}
}

&.euiImage--allowFullScreen {
&:focus .euiImage__img {
.euiImage__button {
cursor: pointer;

// transition the shadow
transition: all $euiAnimSpeedFast $euiAnimSlightResistance;

&:focus {
outline: 2px solid $euiFocusRingColor;
}

&:hover .euiImage__icon {
visibility: visible;
fill-opacity: 1;
}
}

&:hover .euiImage__caption,
&:focus .euiImage__caption {
&.euiImage--allowFullScreen {
&:hover .euiImage__caption {
text-decoration: underline;
}

&:not(.euiImage--hasShadow):hover,
&:not(.euiImage--hasShadow):focus {
.euiImage__img {
@include euiBottomShadowMedium;
}
}

&.euiImage--hasShadow:hover,
&.euiImage--hasShadow:focus {
.euiImage__img {
@include euiBottomShadow;
}
&:not(.euiImage--hasShadow) .euiImage__button:hover,
&:not(.euiImage--hasShadow) .euiImage__button:focus {
@include euiBottomShadowMedium;
}

.euiImage__img {
cursor: pointer;

// transition the shadow
transition: all $euiAnimSpeedFast $euiAnimSlightResistance;
&.euiImage--hasShadow .euiImage__button:hover,
&.euiImage--hasShadow .euiImage__button:focus {
@include euiBottomShadow;
}
}

Expand Down Expand Up @@ -79,6 +74,7 @@
// The image itself is full width within the container.
.euiImage__img {
width: 100%;
vertical-align: middle;
}

.euiImage__caption {
Expand All @@ -103,32 +99,29 @@
max-width: 80vw;
animation: euiImageFullScreen $euiAnimSpeedExtraSlow $euiAnimSlightBounce;

.euiImage-isFullScreen__icon {
&:hover {
.euiImage__button {
@include euiBottomShadow;
}

.euiImage__caption {
text-decoration: underline;
}
}

&__icon {
position: absolute;
right: $euiSize;
top: $euiSize;
}

.euiImage-isFullScreen__img {
&__img {
max-height: 80vh;
max-width: 80vw;
vertical-align: middle;
cursor: pointer;
transition: all $euiAnimSpeedFast $euiAnimSlightResistance;
}

&:hover .euiImage-isFullScreen__img {
@include euiBottomShadow;
cursor: pointer;
}

&:focus .euiImage-isFullScreen__img {
outline: 2px solid $euiFocusRingColor;
}

&:hover .euiImage__caption,
&:focus-within .euiImage__caption {
text-decoration: underline;
}
}

@keyframes euiImageFullScreen {
Expand Down
81 changes: 56 additions & 25 deletions src/components/image/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { EuiOverlayMask } from '../overlay_mask';

import { EuiIcon } from '../icon';

import { EuiI18n } from '../i18n';

import { EuiFocusTrap } from '../focus_trap';

import { keyCodes } from '../../services';
Expand Down Expand Up @@ -112,40 +114,69 @@ export class EuiImage extends Component<EuiImageProps, State> {
const fullScreenDisplay = (
<EuiOverlayMask onClick={this.closeFullScreen}>
<EuiFocusTrap clickOutsideDisables={true}>
<button
type="button"
className="euiImage-isFullScreen"
onClick={this.closeFullScreen}
onKeyDown={this.onKeyDown}>
<figure>
<img src={url} className="euiImage-isFullScreen__img" alt={alt} />
{optionalCaption}

<EuiIcon
type="cross"
color={fullScreenIconColorMap[fullScreenIconColor]}
className="euiImage-isFullScreen__icon"
/>
</figure>
</button>
<figure
className="euiImage euiImage-isFullScreen"
role="figure"
aria-label={caption}>
<EuiI18n
token="euiImage.closeImage"
default="Close image full screen">
myasonik marked this conversation as resolved.
Show resolved Hide resolved
{(closeImage: string) => (
<button
type="button"
aria-label={closeImage}
className="euiImage__button"
onClick={this.closeFullScreen}
onKeyDown={this.onKeyDown}>
<img
src={url}
alt={alt}
className="euiImage-isFullScreen__img"
/>
<EuiIcon
type="cross"
color={fullScreenIconColorMap[fullScreenIconColor]}
className="euiImage-isFullScreen__icon"
/>
</button>
)}
</EuiI18n>
{optionalCaption}
</figure>
</EuiFocusTrap>
</EuiOverlayMask>
);

if (allowFullScreen) {
return (
<button type="button" onClick={this.openFullScreen} className={classes}>
<figure {...rest}>
<img src={url} className="euiImage__img" alt={alt} />
{optionalCaption}
{allowFullScreenIcon}
{isFullScreenActive && fullScreenDisplay}
</figure>
</button>
<figure
className={classes}
role="figure"
aria-label={caption}
{...rest}>
myasonik marked this conversation as resolved.
Show resolved Hide resolved
<EuiI18n token="euiImage.openImage" default="Open image full screen">
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
{(openImage: string) => (
<button
type="button"
aria-label={openImage}
className="euiImage__button"
onClick={this.openFullScreen}>
<img src={url} alt={alt} className="euiImage__img" />
{allowFullScreenIcon}
{isFullScreenActive && fullScreenDisplay}
</button>
)}
</EuiI18n>
{optionalCaption}
</figure>
);
} else {
return (
<figure className={classes} {...rest}>
<figure
className={classes}
role="figure"
aria-label={caption}
{...rest}>
<img src={url} className="euiImage__img" alt={alt} />
{optionalCaption}
</figure>
Expand Down