Skip to content

Commit 9c17114

Browse files
author
Elliot
authored
Fix "ActionListItem without onClick has shadow" bug (#831)
* Fixed shadow appearance without onClick bug * Organized ActionList test suite and added xtest for hover check * Minor layout change to keep header and items aligned * CHANGELOG update
1 parent fb4c4b8 commit 9c17114

File tree

4 files changed

+59
-38
lines changed

4 files changed

+59
-38
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `Menu` closes by default on `MenuItem` click
1313
- Provide `@types/styled-system` as a package dependency
1414

15+
### Fixed
16+
17+
- `ActionListItem` no longer have shadow and cursor: pointer without an onClick
18+
- `ActionListItemColumn` aligns with header columns
19+
1520
## [0.7.28] - 2020-04-20
1621

1722
### Added

packages/components/src/ActionList/ActionList.test.tsx

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,34 @@ const actionListWithNoHeader = (
107107
</ActionList>
108108
)
109109

110+
const handleActionClick = jest.fn()
111+
const handleListItemClick = jest.fn()
112+
const clickableItems = data.map(({ id, name, type }) => {
113+
const availableActions = (
114+
<>
115+
<ActionListItemAction onClick={handleActionClick}>
116+
View Profile
117+
</ActionListItemAction>
118+
</>
119+
)
120+
121+
return (
122+
<ActionListItem
123+
id={String(id)}
124+
key={id}
125+
actions={availableActions}
126+
onClick={handleListItemClick}
127+
>
128+
<ActionListItemColumn>{id}</ActionListItemColumn>
129+
<ActionListItemColumn>{name}</ActionListItemColumn>
130+
<ActionListItemColumn>{type}</ActionListItemColumn>
131+
</ActionListItem>
132+
)
133+
})
134+
const actionListWithClickableRows = (
135+
<ActionList columns={columns}>{clickableItems}</ActionList>
136+
)
137+
110138
describe('ActionList', () => {
111139
let rafSpy: jest.SpyInstance<number, [FrameRequestCallback]>
112140

@@ -118,6 +146,8 @@ describe('ActionList', () => {
118146

119147
afterEach(() => {
120148
rafSpy.mockRestore()
149+
handleActionClick.mockClear()
150+
handleListItemClick.mockClear()
121151
})
122152

123153
describe('General Layout', () => {
@@ -163,43 +193,13 @@ describe('ActionList', () => {
163193
expect(getByText('Game Designer')).toBeInTheDocument()
164194
})
165195

166-
test('Renders action menu on button click and handles clicks on list item and action', () => {
167-
const handleActionClick = jest.fn()
168-
const handleListItemClick = jest.fn()
169-
170-
const clickableItems = data.map(({ id, name, type }) => {
171-
const availableActions = (
172-
<>
173-
<ActionListItemAction onClick={handleActionClick}>
174-
View Profile
175-
</ActionListItemAction>
176-
</>
177-
)
178-
179-
return (
180-
<ActionListItem
181-
id={String(id)}
182-
key={id}
183-
actions={availableActions}
184-
onClick={handleListItemClick}
185-
>
186-
<ActionListItemColumn>{id}</ActionListItemColumn>
187-
<ActionListItemColumn>{name}</ActionListItemColumn>
188-
<ActionListItemColumn>{type}</ActionListItemColumn>
189-
</ActionListItem>
190-
)
191-
})
192-
196+
test('Renders action menu on button click and handles action click', () => {
193197
const { getByRole, getByText, queryByText } = renderWithTheme(
194-
<ActionList columns={columns}>{clickableItems}</ActionList>
198+
actionListWithClickableRows
195199
)
196200

197201
const listItemId = getByText('1')
198202

199-
expect(handleListItemClick.mock.calls.length).toBe(0)
200-
fireEvent.click(listItemId)
201-
expect(handleListItemClick.mock.calls.length).toBe(1)
202-
203203
fireEvent(
204204
listItemId,
205205
new MouseEvent('mouseenter', {
@@ -221,6 +221,24 @@ describe('ActionList', () => {
221221

222222
expect(queryByText('View Profile')).not.toBeInTheDocument()
223223
})
224+
225+
test('Handles item click', () => {
226+
const { getByText } = renderWithTheme(actionListWithClickableRows)
227+
228+
const actionListItemColumn = getByText('1')
229+
230+
expect(handleListItemClick).toHaveBeenCalledTimes(0)
231+
fireEvent.click(actionListItemColumn)
232+
expect(handleListItemClick).toHaveBeenCalledTimes(1)
233+
})
234+
235+
xtest('Item has pointer cursor and shadow when hovering over ActionListItem', () => {
236+
/**
237+
* mouseEnter events off of the fireEvent jest-dom function do not (currently)
238+
* trigger hover styles (i.e. hover pseudo classes) on ActionListItems, which makes
239+
* writing this particularly challenging at the moment.
240+
*/
241+
})
224242
})
225243

226244
describe('Sorting', () => {
@@ -252,7 +270,7 @@ describe('ActionList', () => {
252270
})
253271
})
254272

255-
describe.only('Selecting', () => {
273+
describe('Selecting', () => {
256274
const onSelect = jest.fn()
257275
const actionListWithSelect = (
258276
<ActionList columns={columns} canSelect onSelect={onSelect}>

packages/components/src/ActionList/ActionListItem.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ const ActionListItemInternal: FC<ActionListItemProps> = ({
5353
)
5454

5555
const handleOnSelect = () => onClickRowSelect && onSelect && onSelect(id)
56-
const handleOnClick = (event: React.MouseEvent<HTMLDivElement>) => {
57-
onClick && onClick(event)
58-
}
56+
5957
const handleClick = disabled
6058
? undefined
6159
: onClickRowSelect
6260
? handleOnSelect
63-
: handleOnClick
61+
: onClick || undefined
6462

6563
const handleMenuClick = (event: React.MouseEvent<HTMLElement>) => {
6664
event.stopPropagation()

packages/components/src/ActionList/ActionListItemColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ export const ActionListItemColumn = styled(ActionListItemColumnLayout)<
6666
display: ${(props) => (props.indicator ? 'flex' : undefined)};
6767
font-size: ${(props) => props.theme.fontSizes.xsmall};
6868
word-break: break-all;
69+
overflow: hidden;
6970
7071
${ActionListItemColumnInnerLayout} {
7172
display: flex;
7273
flex-direction: column;
7374
justify-content: center;
74-
overflow: hidden;
7575
}
7676
`

0 commit comments

Comments
 (0)