[fix] Allow href 'target' string to start with underscore

Fix #1963
Close #1937
This commit is contained in:
Nicolas Gallagher
2021-03-29 12:44:27 -07:00
parent 92f577ea26
commit 71f1e9bf3a
5 changed files with 35 additions and 2 deletions
@@ -107,6 +107,15 @@ exports[`components/Text prop "hrefAttrs" requires "href" 1`] = `
/>
`;
exports[`components/Text prop "hrefAttrs" target variant is set 1`] = `
<a
class="css-reset-4rbku5 css-text-901oao"
dir="auto"
href="https://example.com"
target="_blank"
/>
`;
exports[`components/Text prop "hrefAttrs" value is set 1`] = `
<a
class="css-reset-4rbku5 css-text-901oao"
@@ -83,6 +83,14 @@ describe('components/Text', () => {
const hrefAttrs = {
download: 'filename.jpg',
rel: 'nofollow',
target: '_blank'
};
const { container } = render(<Text href="https://example.com" hrefAttrs={hrefAttrs} />);
expect(container.firstChild).toMatchSnapshot();
});
test('target variant is set', () => {
const hrefAttrs = {
target: 'blank'
};
const { container } = render(<Text href="https://example.com" hrefAttrs={hrefAttrs} />);
+2 -2
View File
@@ -131,8 +131,8 @@ const Text = forwardRef<TextProps, *>((props, forwardedRef) => {
if (rel != null) {
supportedProps.rel = rel;
}
if (typeof target === 'string' && target.charAt(0) !== '_') {
supportedProps.target = '_' + target;
if (typeof target === 'string') {
supportedProps.target = target.charAt(0) !== '_' ? '_' + target : target;
}
}
@@ -95,6 +95,14 @@ exports[`components/View prop "hrefAttrs" requires "href" 1`] = `
/>
`;
exports[`components/View prop "hrefAttrs" target variant is set 1`] = `
<a
class="css-reset-4rbku5 css-view-1dbjc4n"
href="https://example.com"
target="_blank"
/>
`;
exports[`components/View prop "hrefAttrs" value is set 1`] = `
<a
class="css-reset-4rbku5 css-view-1dbjc4n"
@@ -116,6 +116,14 @@ describe('components/View', () => {
expect(container.firstChild).toMatchSnapshot();
});
test('target variant is set', () => {
const hrefAttrs = {
target: 'blank'
};
const { container } = render(<View href="https://example.com" hrefAttrs={hrefAttrs} />);
expect(container.firstChild).toMatchSnapshot();
});
test('null values are excluded', () => {
const hrefAttrs = {
download: null,