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

Invalid HTML IDs #1051

Open
tillsanders opened this issue Nov 25, 2024 · 0 comments
Open

Invalid HTML IDs #1051

tillsanders opened this issue Nov 25, 2024 · 0 comments
Labels
awaiting triage The issue is not reviewed by the maintainers bug Something isn't working

Comments

@tillsanders
Copy link

Each day in the calendar is given an HTML id with it's date. This is very handy, e.g. for styling. However, these ids are invalid because they start with a digit. This is an excerpt of the HTML generated by VueDatePicker:

<div class="dp__calendar_row" role="row">
	<div id="2024-11-25" role="gridcell" class="dp__calendar_item" tabindex="0" data-test-id="Mon Nov 25 2024 00:00:00 GMT+0100 (Central European Standard Time)">
		<div class="dp__cell_inner dp__pointer dp__today dp__date_hover">25</div>
	</div>
	<div id="2024-11-26" role="gridcell" class="dp__calendar_item" tabindex="0" data-test-id="Tue Nov 26 2024 00:00:00 GMT+0100 (Central European Standard Time)">
		<div class="dp__cell_inner dp__pointer dp--future dp__date_hover">26</div>
	</div>
	<!-- [...] -->
</div>

As you can see, the ids assigned are the year, month and day with hyphens in between, e.g. 2024-11-25. This is not a valid id as per the CSS standard (https://developer.mozilla.org/en-US/docs/Web/CSS/ident).

This can cause unexpected problems. For example, running this code will yield an error in the console:

document.querySelector('#2024-11-25')
Uncaught DOMException: Document.querySelector: '#2024-11-25' is not a valid selector

It is possible to escape the first digit (#\2024-11-25). This will silence the error but the result will be null.

Tested with Firefox 132 and VueDatePicker v10.0.0.

Solution

Prefix the ids with a string. E.g. dp-.

@tillsanders tillsanders added awaiting triage The issue is not reviewed by the maintainers bug Something isn't working labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting triage The issue is not reviewed by the maintainers bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant