Reakit: Should [data] attributes be prefixed with "reakit-"?

Created on 20 Apr 2020  路  3Comments  路  Source: reakit/reakit

data-enter and data-leave are currently unprefixed which is supprising to me because all libraries I've worked with have these kinds of props prefixed under some namespace, presumable to prevent collisions.

What do we think about prefixing these props with reakit-?

discussion stale

Most helpful comment

Those attributes are part of the component API. My understanding is that, the same way we don't prefix component props, we shouldn't prefix those data-* attributes.

If it causes name collisions, users can change them:

import { useDisclosureState, Disclosure, DisclosureContent } from "reakit";

function Example() {
  const disclosure = useDisclosureState({ animated: true });
  return (
    <>
      <Disclosure {...disclosure}>Toggle</Disclosure>
      <DisclosureContent {...disclosure}>
        {({ "data-leave": leave, "data-enter": enter, ...contentHTMLProps }) => (
          <ComponentThatAlreadyHasDataLeave
            {...contentHTMLProps}
            data-animation-leave={leave}
            data-animation-enter={enter}
          />
        )}
      </DisclosureContent>
    </>
  );
}

Also, for other component libraries or design systems using Reakit as an implementation detail, I wouldn't like to pollute the API with more reakit (by default as they could use the same approach above to overwrite it).

That said, we can leave this open and wait to hear other folks. I'm totally open for prefixing data-* in v2 if this represents a problem. 馃檪

All 3 comments

Hey @tom-sherman :wave:,

Thank you for opening an issue. We'll get back to you as soon as we can.
Please, consider supporting us on Open Collective. We give a special attention to issues opened by backers.

If you use Reakit at work, you can also ask your company to sponsor us :heart:.

Those attributes are part of the component API. My understanding is that, the same way we don't prefix component props, we shouldn't prefix those data-* attributes.

If it causes name collisions, users can change them:

import { useDisclosureState, Disclosure, DisclosureContent } from "reakit";

function Example() {
  const disclosure = useDisclosureState({ animated: true });
  return (
    <>
      <Disclosure {...disclosure}>Toggle</Disclosure>
      <DisclosureContent {...disclosure}>
        {({ "data-leave": leave, "data-enter": enter, ...contentHTMLProps }) => (
          <ComponentThatAlreadyHasDataLeave
            {...contentHTMLProps}
            data-animation-leave={leave}
            data-animation-enter={enter}
          />
        )}
      </DisclosureContent>
    </>
  );
}

Also, for other component libraries or design systems using Reakit as an implementation detail, I wouldn't like to pollute the API with more reakit (by default as they could use the same approach above to overwrite it).

That said, we can leave this open and wait to hear other folks. I'm totally open for prefixing data-* in v2 if this represents a problem. 馃檪

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

codyaverett picture codyaverett  路  4Comments

youknowriad picture youknowriad  路  6Comments

Slapbox picture Slapbox  路  5Comments

diegohaz picture diegohaz  路  4Comments

stphnnnn picture stphnnnn  路  4Comments