Skip to content

Commit

Permalink
[ActionList/Item] Fix disabling ActionList Item when url prop is pass…
Browse files Browse the repository at this point in the history
…ed (#3979)

* Disable ActionList Item when url prop is passed

* Update UNRELEASED.md

* Update to set url and onClick to null + Add tests
  • Loading branch information
Colin Barnes authored and sylvhama committed Mar 26, 2021
1 parent c80960c commit 1d46a0d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Fixed click propagation that was preventing the `Tooltip` to open when used as suffix on a `TextField` ([#3956](https://github.com/Shopify/polaris-react/issues/3956))
- Made items in `ActionList` more clear in high contrast mode ([#3971](https://github.com/Shopify/polaris-react/pull/3971))
- Fixed the MediaCard thumbnail’s corner roundness, so it wouldn’t overflow out of the parent Card ([#3974](https://github.com/Shopify/polaris-react/issues/3974))
- Fixed `ActionList` `Item` not disabling properly when url prop is passed ([#3979](https://github.com/Shopify/polaris-react/pull/3979))

### Documentation

Expand Down
4 changes: 2 additions & 2 deletions src/components/ActionList/components/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ export function Item({
const control = url ? (
<UnstyledLink
id={id}
url={url}
url={disabled ? null : url}
className={className}
external={external}
aria-label={accessibilityLabel}
onClick={onAction}
onClick={disabled ? null : onAction}
>
{contentElement}
</UnstyledLink>
Expand Down
14 changes: 14 additions & 0 deletions src/components/ActionList/components/Item/tests/Item.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ describe('<Item />', () => {
mockAccessibilityLabel,
);
});

it('passes `url` as null to `<UnstyledLink />` when disabled', () => {
const item = mountWithApp(<Item url="https://shopify.com" disabled />);

expect(item.find(UnstyledLink)!.prop('url')).toBeNull();
});

it('passes `onClick` as null to `<UnstyledLink />` when disabled', () => {
const item = mountWithApp(
<Item onAction={noop} disabled url="https://shopify.com" />,
);

expect(item.find(UnstyledLink)!.prop('onClick')).toBeNull();
});
});

function noop() {}

0 comments on commit 1d46a0d

Please sign in to comment.