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

Can HTML5 "data-*" custom attributes be targeted instead? #207

Open
jschrab opened this issue Oct 30, 2019 · 2 comments
Open

Can HTML5 "data-*" custom attributes be targeted instead? #207

jschrab opened this issue Oct 30, 2019 · 2 comments

Comments

@jschrab
Copy link

jschrab commented Oct 30, 2019

In dom.ts, getDateAttribute(...) fetches the custom datetime attribute...

export function getDateAttribute(node: HTMLElement): string {
  return node.getAttribute('datetime');
}

But AFAIK, HTML5 would prefer the use of data- prefixed custom attributes. I am in a development environment that returns proxy objects instead of direct DOM references. The handler for this proxy is strict and does not pass back any value to the datetime attribute. If the target attribute were (optionally) data-datetime, that would work and be more HTML5-ish.

Perhaps...?

export function getDateAttribute(node: HTMLElement): string {
  return node.getAttribute('datetime') || node.dataset.datetime;
}

...for backwards compatibility? More validation is probably necessary for the above.

@jschrab
Copy link
Author

jschrab commented Oct 31, 2019

Actually, being able to define what the name of the attribute should be would be even better:

export function getDateAttribute(node: HTMLElement): string {
  return node.getAttribute(this.dateTimeAttributeName);
}

...which would still work if the attribute was data-datetime.

@nicholaschiang
Copy link

When using timeago.js with React and Typescript, you're unable to specify the datetime attribute (but you are able to specify any custom data-* attributes, as suggested by @jschrab).

Current fix for me was to just use the timeago-react package instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants