Skip to content

relative-time doesn't render anything without having an initial datetime value #289

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

Closed
cheshire137 opened this issue Aug 22, 2024 · 0 comments · Fixed by #290
Closed

relative-time doesn't render anything without having an initial datetime value #289

cheshire137 opened this issue Aug 22, 2024 · 0 comments · Fixed by #290

Comments

@cheshire137
Copy link
Member

I spoke a bit with @keithamus about this. I have a hidden <relative-time> element on the page that I want to programmatically reveal after I've set its datetime attribute. I learned that if datetime is omitted or left blank, then when I do setAttribute('datetime', nothing appears for the element on the page, and the <relative-time> element has a size of 0x0. If I manually call .update() on the element via my browser console, the '1 minute ago' or whatever timestamp appears as expected. 👍

I have a workaround in that I can set datetime to the current time's ISO8601 string in the static page HTML. Then I found I can programmatically change the datetime attribute value and the updated timestamp appears like I want.

My use case is that I have a <relative-time> element that I want to populate once I know the right timestamp. I'm getting a timestamp from localstorage, so I have to check if the value exists and, if so, update datetime on the relative-time and display it.

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

Successfully merging a pull request may close this issue.

1 participant