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

data-* attribute selection doesn't work #7

Closed
4 tasks done
hesxenon opened this issue Jan 25, 2024 · 9 comments
Closed
4 tasks done

data-* attribute selection doesn't work #7

hesxenon opened this issue Jan 25, 2024 · 9 comments
Labels
💪 phase/solved Post is done

Comments

@hesxenon
Copy link

Initial checklist

Affected packages and versions

hast-util-select@6

Link to runnable example

https://jsbin.com/lihidasupa/1/edit?html,console

Steps to reproduce

  1. create an element with a data-* attribute
  2. try to find it with an attribute selector

Expected behavior

Element should be found

Actual behavior

Element isn't found

Affected runtime and version

chromium@Version 121.0.6167.85 (Official Build) Arch Linux (64-bit)

Affected package manager and version

No response

Affected OS and version

No response

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 25, 2024
@hesxenon
Copy link
Author

hello there, it's me again :P just tried to find an element based on a data-* attribute and it's not being found.

I'm starting to think you have some issue with dashes 😄

@wooorm
Copy link
Member

wooorm commented Jan 25, 2024

Hi again!

yes, in hast, the properties are camelcased.
This behavior is expected, and I’m pretty sure even tested.
So the element is wrong. Why are you getting dashes in props?

A lot of our previous conversation applies here. About jsx. About what hastscript does.

@hesxenon
Copy link
Author

ah dang it, I mixed up the camelcasing. You see, I had that thought as well but didn't change the property to camelcase in the test setup but the selector 🤦‍♀️.

I'm getting the dashed properties for the same reason as in the other issue - because I'm explicitly assigning them as a workaround for the "2nd argument type value" problem.

Anyway, in that case I think this issue can be closed because it either doesn't apply to this repo or because I can fix it on my end. Sorry for the interruption.

This comment has been minimized.

@wooorm
Copy link
Member

wooorm commented Jan 27, 2024

because I'm explicitly assigning them as a workaround for the "2nd argument type value" problem.

This was already solved! You can run npm update

Anyway, in that case I think this issue can be closed because it either doesn't apply to this repo or because I can fix it on my end. Sorry for the interruption.

👍

@wooorm wooorm added the 💪 phase/solved Post is done label Jan 27, 2024
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Jan 27, 2024
@mordechaim
Copy link

mordechaim commented Feb 29, 2024

I'm not sure I follow. Using data-* props is quite standard and works with the dash in JSX as well (it's not camel cased). But I cannot seem to select them even with the latest version of hast-util-select.

Using [dataName] for instance, doesn't work either, so there's no way of selecting at all with data attributes.

@hesxenon
Copy link
Author

@mordechaim you can see here that it does work as expected - the question is: what does your tree look like?

@mordechaim
Copy link

Ah for me the tree is like:

  const tree = {
    type: "element",
    properties: {
      name: "foo",
      "data-name": "foo"
    }
  }

@ChristianMurphy
Copy link
Member

@mordechaim properties are camel cased.
If you are manually injecting the node, it should look like:

  const tree = {
    type: "element",
    properties: {
      name: "foo",
      "dataName": "foo"
    }
  }

You can use a hast parser on a real document to see what properties should look like, for example: https://stackblitz.com/edit/github-b1fwzc?file=src%2Findex.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

No branches or pull requests

4 participants