Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] feat: spread data-* props to HTML elements #4180

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/src/common/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ export function removeNonHTMLProps(

return invalidProps.reduce(
(prev, curr) => {
// Props with hyphens (e.g. data-*) are always considered html props
if (curr.indexOf("-") !== -1) {
return prev;
}

if (prev.hasOwnProperty(curr)) {
delete (prev as any)[curr];
}
Expand Down
5 changes: 5 additions & 0 deletions packages/core/test/buttons/buttonTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ function buttonTestSuite(component: React.ComponentClass<any>, tagName: string)
assert.equal(wrapper.text(), "some text");
});

it("renders the button text prop", () => {
const wrapper = mount(<Button data-test-foo="bar" />);
assert.isTrue(wrapper.find('[data-test-foo="bar"]').exists());
});

it("wraps string children in spans", () => {
// so text can be hidden when loading
const wrapper = button({}, true, "raw string", <em>not a string</em>);
Expand Down