Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #140003
    chrisdavies71
    Participant

    Hi Zac,

    I am looking to use the useInstanceId hook https://github.com/WordPress/gutenberg/tree/master/packages/compose/src/hooks/use-instance-id

    I have the following HTML in my plugin:

    <div className="card-header collapsed" data-toggle="collapse" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne" id="headingOne">

    I would like the href="#collapseOne to be something like href="#collapse-1 with the number being created dynamically. This is for an accordion block which will be repeated multiple times on the page.

    Is useInstanceId the right thing to use and can you point me in the right direction on where to start. Currently all the code is just in a block.js file.

    Regards

    Chris

    #140005
    Zac Gordon
    Keymaster

    It won’t give you IDs like 1,2,3, but it will generate unique IDs for you. What values is it generating for you?

    Can also look at using the native Accordian component if it helps.

    #140006
    chrisdavies71
    Participant

    Hi Zac,

    A native accordion option would be good – looks like it is being developed currently but probably a way off a shipped version.

    As for the ID – In an ideal world I would get something like 1,2,3 but not essential. What I do need is for it to be the same in a couple of places in the code so that the show/hide works. I am building it based on Bootstrap styles.

    Currently I have not started with this as Hooks are completely new to me so no idea where to start.

    Chris

    #140248
    chrisdavies71
    Participant

    Hi Zac,

    Any thoughts on the above?

    Opted for using the clientId instead which works in the edit but comes up as undefined when saved.

    What am I doing wrong here?

    Regards

    Chris

    #140376
    chrisdavies71
    Participant

    Hi Zac,

    I am still struggling with this.

    I have now given up entirely on trying to do this dynamically and gone for a simple Inspector Controls way of adding it.

    I still have the issue though that it works in the edit but not the save.

    Chris

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.