@lumx/react 3.19.1-alpha.0 → 3.19.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "url": "https://github.com/lumapps/design-system/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@lumx/core": "^3.19.1-alpha.0",
10
- "@lumx/icons": "^3.19.1-alpha.0",
9
+ "@lumx/core": "^3.19.1-alpha.1",
10
+ "@lumx/icons": "^3.19.1-alpha.1",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "classnames": "^2.3.2",
@@ -105,5 +105,5 @@
105
105
  "build:storybook": "storybook build"
106
106
  },
107
107
  "sideEffects": false,
108
- "version": "3.19.1-alpha.0"
108
+ "version": "3.19.1-alpha.1"
109
109
  }
@@ -147,7 +147,7 @@ export const ButtonRoot = forwardRef<ButtonRootProps, HTMLButtonElement | HTMLAn
147
147
 
148
148
  return (
149
149
  <RawClickable
150
- as={linkAs || forwardedProps.href ? 'a' : 'button'}
150
+ as={linkAs || (forwardedProps.href ? 'a' : 'button')}
151
151
  {...forwardedProps}
152
152
  {...disabledStateProps}
153
153
  aria-disabled={isAnyDisabled}
@@ -85,7 +85,7 @@ export const Link = forwardRef<LinkProps, HTMLAnchorElement | HTMLButtonElement>
85
85
  return (
86
86
  <RawClickable
87
87
  ref={ref as any}
88
- as={linkAs || forwardedProps.href ? 'a' : 'button'}
88
+ as={linkAs || (forwardedProps.href ? 'a' : 'button')}
89
89
  {...forwardedProps}
90
90
  {...disabledStateProps}
91
91
  className={classNames(
@@ -116,7 +116,7 @@ export const ListItem = forwardRef<ListItemProps, HTMLLIElement>((props, ref) =>
116
116
  {isClickable({ linkProps, onItemSelected }) ? (
117
117
  /* Clickable list item */
118
118
  <RawClickable
119
- as={linkAs || linkProps.href ? 'a' : 'button'}
119
+ as={linkAs || (linkProps.href ? 'a' : 'button')}
120
120
  {...linkProps}
121
121
  {...disabledStateProps}
122
122
  className={classNames(
@@ -113,7 +113,7 @@ export const SideNavigationItem = forwardRef<SideNavigationItemProps, HTMLLIElem
113
113
  {shouldSplitActions ? (
114
114
  <div className={`${CLASSNAME}__wrapper`}>
115
115
  <RawClickable
116
- as={linkAs || linkProps?.href ? 'a' : 'button'}
116
+ as={linkAs || (linkProps?.href ? 'a' : 'button')}
117
117
  {...(linkProps as any)}
118
118
  className={`${CLASSNAME}__link`}
119
119
  onClick={onClick}
@@ -134,7 +134,7 @@ export const SideNavigationItem = forwardRef<SideNavigationItemProps, HTMLLIElem
134
134
  </div>
135
135
  ) : (
136
136
  <RawClickable
137
- as={linkAs || linkProps?.href ? 'a' : 'button'}
137
+ as={linkAs || (linkProps?.href ? 'a' : 'button')}
138
138
  {...linkProps}
139
139
  className={`${CLASSNAME}__link`}
140
140
  onClick={onClick}
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { DisabledStateProvider } from '@lumx/react/utils';
4
4
  import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
5
5
  import { queryByClassName } from '@lumx/react/testing/utils/queries';
6
- import { fireEvent, render } from '@testing-library/react';
6
+ import { fireEvent, render, screen } from '@testing-library/react';
7
7
  import { Thumbnail, ThumbnailProps } from './Thumbnail';
8
8
 
9
9
  const CLASSNAME = Thumbnail.className as string;
@@ -28,8 +28,19 @@ describe(`<${Thumbnail.displayName}>`, () => {
28
28
  },
29
29
  });
30
30
 
31
- describe('disabled state', () => {
32
- it('should not be clickable when disabled from context', () => {
31
+ describe('clickable button', () => {
32
+ it('should render clickable button', async () => {
33
+ const onClick = jest.fn();
34
+ const { thumbnail } = setup({ onClick, alt: 'Name' });
35
+ const button = screen.getByRole('button', { name: 'Name' });
36
+ expect(button).toBe(thumbnail);
37
+ expect(button).toHaveAttribute('type', 'button');
38
+
39
+ fireEvent.click(thumbnail as HTMLElement);
40
+ expect(onClick).toHaveBeenCalled();
41
+ });
42
+
43
+ it('should not render button in disabled context', () => {
33
44
  const onClick = jest.fn();
34
45
  const { thumbnail, container } = setup(
35
46
  { onClick, 'aria-label': 'thumbnail' },
@@ -47,8 +58,21 @@ describe(`<${Thumbnail.displayName}>`, () => {
47
58
  fireEvent.click(thumbnail as HTMLElement);
48
59
  expect(onClick).not.toHaveBeenCalled();
49
60
  });
61
+ });
62
+
63
+ describe('clickable link', () => {
64
+ it('should render clickable link', async () => {
65
+ const onClick = jest.fn((evt) => evt.preventDefault());
66
+ const { thumbnail } = setup({ linkProps: { href: '#' }, onClick, alt: 'Name' });
67
+ const link = screen.getByRole('link', { name: 'Name' });
68
+ expect(link).toBe(thumbnail);
69
+ expect(link).toHaveAttribute('href', '#');
70
+
71
+ fireEvent.click(thumbnail as HTMLElement);
72
+ expect(onClick).toHaveBeenCalled();
73
+ });
50
74
 
51
- it('should have no href when disabled from context', () => {
75
+ it('should not render link in disabled context', () => {
52
76
  const { container, thumbnail } = setup(
53
77
  { linkAs: 'a', linkProps: { href: '#' }, 'aria-label': 'thumbnail' },
54
78
  {
@@ -151,12 +151,16 @@ export const Thumbnail = forwardRef<ThumbnailProps>((props, ref) => {
151
151
  imageErrorStyle.display = 'none';
152
152
  }
153
153
 
154
- const isClickable = !isAnyDisabled && (linkProps?.href || linkAs || forwardedProps.onClick);
154
+ const isLink = linkProps?.href || linkAs;
155
+ const isClickable = !isAnyDisabled && (isLink || forwardedProps.onClick);
155
156
 
156
157
  const Wrapper: any = isClickable ? RawClickable : 'div';
157
158
  const wrapperProps = { ...forwardedProps };
158
159
  if (isClickable) {
159
- Object.assign(wrapperProps, linkProps, { as: linkAs || linkProps?.href ? 'a' : 'button' }, disabledStateProps);
160
+ Object.assign(wrapperProps, { as: linkAs || (linkProps?.href ? 'a' : 'button') }, disabledStateProps);
161
+ if (isLink) {
162
+ Object.assign(wrapperProps, linkProps);
163
+ }
160
164
  wrapperProps['aria-label'] = forwardedProps['aria-label'] || alt;
161
165
  }
162
166