Skip to content

Commit

Permalink
Merge pull request #26 from biirus/master
Browse files Browse the repository at this point in the history
fix(react): pass data- and aria-attributes to React component (#25)
  • Loading branch information
jthoms1 authored Feb 27, 2020
2 parents 63cdb52 + 06a6ffe commit d770a61
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ export const createReactComponent = <PropType, ElementType>(tagName: string) =>
const { children, forwardedRef, style, className, ref, ...cProps } = this.props;

const propsToPass = Object.keys(cProps).reduce((acc, name) => {
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
const isEventProp = name.indexOf('on') === 0 && name[2] === name[2].toUpperCase();
const isDataProp = name.indexOf('data-') === 0;
const isAriaProp = name.indexOf('aria-') === 0;

if (isEventProp) {
const eventName = name.substring(2).toLowerCase();
if (isCoveredByReact(eventName)) {
(acc as any)[name] = (cProps as any)[name];
}
} else if (isDataProp || isAriaProp) {
(acc as any)[name] = (cProps as any)[name];
}
return acc;
}, {});
Expand Down

0 comments on commit d770a61

Please sign in to comment.