Skip to content

Generated ids starting with 0-9 are not valid as CSS selectors/classesΒ #2739

Open

Description

@medeaoblongata

Subject of the issue/enhancement/features

I notice that all those long generated hexy-looking ids, while legal in HTML, are actually not valid CSS selectors if they begin with anything but an alphabetical character. So something like document.querySelector(referenceToSomeGeneratedAdaptId) appearing in a custom component is likely to throw a DOMException.

A safer approach would be to ensure that the generated ID begins with a character which is a legal starting character for CSS selectors.

Steps to reproduce

Make some content (e.g. in authoring tool, or just with framework) such that an ID is generated.
Make a bare bones custom component (or just a few lines of js, or even a one-liner in the console) which uses querySelector to hook up to that ID.

Expected behaviour

querySelector/querySelectorAll should accept all generated IDs without causing a DOMException.

Actual behaviour

In many/most cases, the ID will begin with a numeral (0-9), causing a DOMException, although it's hexadecimal, so there's a smaller chance it starts with a-f, which is legal as a CSS selector.

Activity

  1. moloko commented on Oct 19, 2020

    @moloko
    Contributor

    I propose that we drop these altogether in Adapt Framework v6. We have had the data-adapt-id attribute (that contains the page/article/block/component id) in place for a while now, people should switch to targetting that or using the _classes attribute to add custom styling.

  2. added this to the milestone on Oct 19, 2020
  3. moloko commented on Apr 15, 2021

    @moloko
    Contributor

    Just to note this also causes a bug with Adapt.navigateToElement.

    From the menu, Adapt.navigateToElement('co-05'); should take you to page co-05 but instead it just scrolls to that menu item.

    Definitely remove these IDs in Adapt v6!

  4. changed the title [-]Generated ids starting with 0-9 are not valid as CSS selectors[/-] [+]Generated ids starting with 0-9 are not valid as CSS selectors/classes[/+] on Apr 15, 2021
  5. removed this from the milestone on Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions