Skip to content

Commit 78cd32e

Browse files
committed
Revert "feat(thumbnail): fix thumbnail avatar and userblock a11y"
This reverts commit abbc4a2.
1 parent 3903590 commit 78cd32e

File tree

10 files changed

+194
-461
lines changed

10 files changed

+194
-461
lines changed

packages/lumx-core/src/scss/components/thumbnail/_index.scss

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@
103103
/* Thumbnail states
104104
========================================================================== */
105105

106-
.#{$lumx-base-prefix}-thumbnail--is-clickable {
106+
.#{$lumx-base-prefix}-thumbnail[tabindex='0'] {
107107
position: relative;
108-
display: block;
109108
cursor: pointer;
110109

111110
&::after {
@@ -120,8 +119,7 @@
120119
pointer-events: none;
121120
}
122121

123-
&:hover::after,
124-
&:focus::after {
122+
&:hover::after {
125123
@include lumx-state(lumx-base-const('state', 'HOVER'), lumx-base-const('emphasis', 'LOW'), 'dark');
126124
}
127125

@@ -130,19 +128,19 @@
130128
}
131129
}
132130

133-
.#{$lumx-base-prefix}-thumbnail--variant-rounded.#{$lumx-base-prefix}-thumbnail--is-clickable {
131+
.#{$lumx-base-prefix}-thumbnail--variant-rounded.#{$lumx-base-prefix}-thumbnail[tabindex='0'] {
134132
&[data-focus-visible-added]::after {
135133
border-radius: var(--lumx-border-radius);
136134
}
137135
}
138136

139-
.#{$lumx-base-prefix}-thumbnail--theme-light.#{$lumx-base-prefix}-thumbnail--is-clickable {
137+
.#{$lumx-base-prefix}-thumbnail--theme-light.#{$lumx-base-prefix}-thumbnail[tabindex='0'] {
140138
&[data-focus-visible-added]::after {
141139
@include lumx-state(lumx-base-const('state', 'FOCUS'), lumx-base-const('emphasis', 'LOW'), 'dark');
142140
}
143141
}
144142

145-
.#{$lumx-base-prefix}-thumbnail--theme-dark.#{$lumx-base-prefix}-thumbnail--is-clickable {
143+
.#{$lumx-base-prefix}-thumbnail--theme-dark.#{$lumx-base-prefix}-thumbnail[tabindex='0'] {
146144
&[data-focus-visible-added]::after {
147145
@include lumx-state(lumx-base-const('state', 'FOCUS'), lumx-base-const('emphasis', 'LOW'), 'light');
148146
}

packages/lumx-core/src/scss/components/user-block/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
color: lumx-color-variant('light', 'N');
5050
}
5151

52-
&--is-clickable {
52+
&[tabindex='0'] {
5353
#{$self}--theme-light & {
5454
@include lumx-link('dark');
5555
}

packages/lumx-react/src/components/avatar/Avatar.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ export interface AvatarProps extends GenericProps {
3636
ThumbnailProps,
3737
'image' | 'alt' | 'size' | 'theme' | 'align' | 'fillHeight' | 'variant' | 'aspectRatio'
3838
>;
39-
/** Props to pass to the link wrapping the thumbnail. */
40-
linkProps?: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
41-
/** Custom react component for the link (can be used to inject react router Link). */
42-
linkAs?: 'a' | any;
4339
}
4440

4541
/**
@@ -79,8 +75,6 @@ export const Avatar: Comp<AvatarProps, HTMLDivElement> = forwardRef((props, ref)
7975
size,
8076
theme,
8177
thumbnailProps,
82-
linkProps,
83-
linkAs,
8478
...forwardedProps
8579
} = props;
8680

@@ -91,8 +85,6 @@ export const Avatar: Comp<AvatarProps, HTMLDivElement> = forwardRef((props, ref)
9185
className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, size, theme }))}
9286
>
9387
<Thumbnail
94-
linkProps={linkProps}
95-
linkAs={linkAs}
9688
className={`${CLASSNAME}__thumbnail`}
9789
onClick={onClick}
9890
onKeyPress={onKeyPress}

packages/lumx-react/src/components/thumbnail/Thumbnail.stories.tsx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,13 @@ import { boolean, select, text } from '@storybook/addon-knobs';
1818
import { enumKnob } from '@lumx/react/stories/knobs/enumKnob';
1919
import { focusKnob } from '@lumx/react/stories/knobs/focusKnob';
2020
import { sizeKnob } from '@lumx/react/stories/knobs/sizeKnob';
21-
import classNames from 'classnames';
2221

2322
export default { title: 'LumX components/thumbnail/Thumbnail' };
2423

2524
export const Default = () => <Thumbnail alt="Image alt text" image={imageKnob()} size={Size.xxl} />;
2625

2726
export const Clickable = () => <Thumbnail alt="Click me" image={imageKnob()} size={Size.xxl} onClick={console.log} />;
2827

29-
export const ClickableLink = () => (
30-
<Thumbnail alt="Click me" image={imageKnob()} size={Size.xxl} linkProps={{ href: 'https://google.fr' }} />
31-
);
32-
33-
const CustomLinkComponent = (props: any) => (
34-
<a {...props} className={classNames('custom-link-component', props.className)}>
35-
{props.children}
36-
</a>
37-
);
38-
39-
export const ClickableCustomLink = () => (
40-
<Thumbnail
41-
alt="Click me"
42-
image={imageKnob()}
43-
size={Size.xxl}
44-
linkAs={CustomLinkComponent}
45-
linkProps={{ href: 'https://google.fr', className: 'custom-class-name' }}
46-
/>
47-
);
48-
4928
export const DefaultFallback = () => <Thumbnail alt="foo" image="foo" />;
5029

5130
export const IconFallback = () => <Thumbnail alt="foo" image="foo" fallback={mdiAbTesting} />;

packages/lumx-react/src/components/thumbnail/Thumbnail.test.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ import 'jest-enzyme';
55
import { commonTestsSuite, itShouldRenderStories } from '@lumx/react/testing/utils';
66

77
import { Thumbnail, ThumbnailProps } from './Thumbnail';
8-
import {
9-
Clickable,
10-
ClickableCustomLink,
11-
ClickableLink,
12-
CustomFallback,
13-
Default,
14-
DefaultFallback,
15-
IconFallback,
16-
WithBadge,
17-
} from './Thumbnail.stories';
8+
import { Clickable, CustomFallback, Default, DefaultFallback, IconFallback, WithBadge } from './Thumbnail.stories';
189

1910
const CLASSNAME = Thumbnail.className as string;
2011

@@ -31,16 +22,7 @@ describe(`<${Thumbnail.displayName}>`, () => {
3122
// 1. Test render via snapshot.
3223
describe('Snapshots and structure', () => {
3324
itShouldRenderStories(
34-
{
35-
Default,
36-
Clickable,
37-
ClickableLink,
38-
ClickableCustomLink,
39-
DefaultFallback,
40-
CustomFallback,
41-
IconFallback,
42-
WithBadge,
43-
},
25+
{ Default, Clickable, DefaultFallback, CustomFallback, IconFallback, WithBadge },
4426
Thumbnail,
4527
);
4628
});

packages/lumx-react/src/components/thumbnail/Thumbnail.tsx

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { isInternetExplorer } from '@lumx/react/utils/isInternetExplorer';
2020
import { mergeRefs } from '@lumx/react/utils/mergeRefs';
2121
import { useFocusPoint } from '@lumx/react/components/thumbnail/useFocusPoint';
2222
import { useImageLoad } from '@lumx/react/components/thumbnail/useImageLoad';
23+
import { useClickable } from '@lumx/react/components/thumbnail/useClickable';
2324
import { FocusPoint, ThumbnailSize, ThumbnailVariant } from './types';
2425

2526
type ImgHTMLProps = ImgHTMLAttributes<HTMLImageElement>;
@@ -62,10 +63,6 @@ export interface ThumbnailProps extends GenericProps {
6263
theme?: Theme;
6364
/** Variant of the component. */
6465
variant?: ThumbnailVariant;
65-
/** Props to pass to the link wrapping the thumbnail. */
66-
linkProps?: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
67-
/** Custom react component for the link (can be used to inject react router Link). */
68-
linkAs?: 'a' | any;
6966
}
7067

7168
/**
@@ -112,8 +109,6 @@ export const Thumbnail: Comp<ThumbnailProps> = forwardRef((props, ref) => {
112109
size,
113110
theme,
114111
variant,
115-
linkProps,
116-
linkAs,
117112
...forwardedProps
118113
} = props;
119114
const imgRef = useRef<HTMLImageElement>(null);
@@ -124,44 +119,24 @@ export const Thumbnail: Comp<ThumbnailProps> = forwardRef((props, ref) => {
124119
const isLoading = loadingState === 'isLoading';
125120

126121
const [wrapper, setWrapper] = useState<HTMLElement>();
127-
128-
const isLink = Boolean(linkProps?.href || linkAs);
129-
const isButton = !!forwardedProps.onClick;
130-
const isClickable = isButton || isLink;
131-
132-
let Wrapper: any = 'div';
133-
const wrapperProps = { ...forwardedProps };
134-
if (isLink) {
135-
Wrapper = linkAs || 'a';
136-
Object.assign(wrapperProps, linkProps);
137-
} else if (isButton) {
138-
Wrapper = 'button';
139-
}
122+
const wrapperProps: any = {
123+
...forwardedProps,
124+
ref: mergeRefs(setWrapper, ref),
125+
className: classNames(
126+
className,
127+
handleBasicClasses({ align, aspectRatio, prefix: CLASSNAME, size, theme, variant, hasBadge: !!badge }),
128+
isLoading && wrapper?.getBoundingClientRect()?.height && 'lumx-color-background-dark-L6',
129+
fillHeight && `${CLASSNAME}--fill-height`,
130+
),
131+
// Handle clickable Thumbnail a11y.
132+
...useClickable(props),
133+
};
140134

141135
// Update img style according to focus point and aspect ratio.
142136
const style = useFocusPoint({ image, focusPoint, aspectRatio, imgRef, loadingState, wrapper });
143137

144138
return (
145-
<Wrapper
146-
{...wrapperProps}
147-
ref={mergeRefs(setWrapper, ref) as any}
148-
className={classNames(
149-
linkProps?.className,
150-
className,
151-
handleBasicClasses({
152-
align,
153-
aspectRatio,
154-
prefix: CLASSNAME,
155-
size,
156-
theme,
157-
variant,
158-
isClickable,
159-
hasBadge: !!badge,
160-
}),
161-
isLoading && wrapper?.getBoundingClientRect()?.height && 'lumx-color-background-dark-L6',
162-
fillHeight && `${CLASSNAME}--fill-height`,
163-
)}
164-
>
139+
<div {...wrapperProps}>
165140
<div
166141
className={`${CLASSNAME}__background`}
167142
style={{
@@ -194,7 +169,7 @@ export const Thumbnail: Comp<ThumbnailProps> = forwardRef((props, ref) => {
194169
))}
195170
{badge &&
196171
React.cloneElement(badge, { className: classNames(`${CLASSNAME}__badge`, badge.props.className) })}
197-
</Wrapper>
172+
</div>
198173
);
199174
});
200175
Thumbnail.displayName = COMPONENT_NAME;

packages/lumx-react/src/components/thumbnail/__snapshots__/Thumbnail.test.tsx.snap

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`<Thumbnail> Snapshots and structure should render story 'Clickable' 1`] = `
4-
<button
5-
className="lumx-thumbnail lumx-thumbnail--size-xxl lumx-thumbnail--theme-light lumx-thumbnail--is-clickable"
4+
<div
5+
className="lumx-thumbnail lumx-thumbnail--size-xxl lumx-thumbnail--theme-light"
66
onClick={[Function]}
7+
onKeyPress={[Function]}
8+
role="button"
9+
tabIndex={0}
710
>
811
<div
912
className="lumx-thumbnail__background"
@@ -22,57 +25,7 @@ exports[`<Thumbnail> Snapshots and structure should render story 'Clickable' 1`]
2225
style={Object {}}
2326
/>
2427
</div>
25-
</button>
26-
`;
27-
28-
exports[`<Thumbnail> Snapshots and structure should render story 'ClickableCustomLink' 1`] = `
29-
<CustomLinkComponent
30-
className="custom-class-name lumx-thumbnail lumx-thumbnail--size-xxl lumx-thumbnail--theme-light lumx-thumbnail--is-clickable"
31-
href="https://google.fr"
32-
>
33-
<div
34-
className="lumx-thumbnail__background"
35-
style={
36-
Object {
37-
"display": undefined,
38-
"visibility": "hidden",
39-
}
40-
}
41-
>
42-
<img
43-
alt="Click me"
44-
className="lumx-thumbnail__image"
45-
loading="lazy"
46-
src="/demo-assets/landscape1.jpg"
47-
style={Object {}}
48-
/>
49-
</div>
50-
</CustomLinkComponent>
51-
`;
52-
53-
exports[`<Thumbnail> Snapshots and structure should render story 'ClickableLink' 1`] = `
54-
<a
55-
className="lumx-thumbnail lumx-thumbnail--size-xxl lumx-thumbnail--theme-light lumx-thumbnail--is-clickable"
56-
href="https://google.fr"
57-
>
58-
<div
59-
className="lumx-thumbnail__background"
60-
style={
61-
Object {
62-
"display": undefined,
63-
"visibility": "hidden",
64-
}
65-
}
66-
>
67-
<img
68-
alt="Click me"
69-
className="lumx-thumbnail__image"
70-
loading="lazy"
71-
src="/demo-assets/landscape1.jpg"
72-
style={Object {}}
73-
/>
74-
</div>
75-
</a>
28+
</div>
7629
`;
7730
7831
exports[`<Thumbnail> Snapshots and structure should render story 'CustomFallback' 1`] = `

0 commit comments

Comments
 (0)