diff --git a/UNRELEASED.md b/UNRELEASED.md index 9c5851de5d3..569d7804dd4 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -16,6 +16,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f ### Bug fixes +- Ensure disabled `Button` components with a `url` prop output valid HTML ([#773](https://github.com/Shopify/polaris-react/pull/773)) + ### Documentation - Added deprecation guidelines ([#853](https://github.com/Shopify/polaris-react/pull/853)) diff --git a/src/components/Button/Button.tsx b/src/components/Button/Button.tsx index de1a38d4f28..0bb015dc550 100644 --- a/src/components/Button/Button.tsx +++ b/src/components/Button/Button.tsx @@ -152,22 +152,32 @@ function Button({ const type = submit ? 'submit' : 'button'; - return url ? ( - - {content} - - ) : ( + if (url) { + return isDisabled ? ( + // Render an `` so toggling disabled/enabled state changes only the + // `href` attribute instead of replacing the whole element. + // eslint-disable-next-line jsx-a11y/anchor-is-valid + + {content} + + ) : ( + + {content} + + ); + } + + return (