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

Add anchor tag support for Page Navigation #101

Open
Rathod-Harshit opened this issue Jun 8, 2023 · 3 comments
Open

Add anchor tag support for Page Navigation #101

Rathod-Harshit opened this issue Jun 8, 2023 · 3 comments

Comments

@Rathod-Harshit
Copy link

Rathod-Harshit commented Jun 8, 2023

Hi,

First if all, thanks for this awesome lib. It has simplified my implementation.

Problem Statement: As a user I want to navigate within the same page using anchor tags.
Type: Enhancement

I am using Hygraph rich-text and as of now, I could not find a way to add id to the div. I want to add id to div so that, I am able to navigate within the page using anchor tags.

Solution: This use case will mostly apply to headings. In Rich text editor I can add a class to heading with prefix anchor- and in the package add an id to div, if classname matches the prefix. Id will be same as classname. (This is not a very good approach, but I can not think of any other solution. )

Enhance https://github.com/hygraph/rich-text/blob/main/packages/react-renderer/src/elements/Class.tsx

@vinnycodes
Copy link

vinnycodes commented Jul 14, 2023

Currently looking for a similar resolution to this as well.
Going to see if posting to their feedback page will yield a faster response.

https://feedback.hygraph.com/148

@Rathod-Harshit
Copy link
Author

Rathod-Harshit commented Jul 14, 2023

Actually, I was able to find a simple work-around.

Lets say we have an h3 with title: Anchor one
then create an unique id as: anchor-one and link it.
Screen Shot 2023-07-14 at 11 45 47 AM

Screen Shot 2023-07-14 at 11 51 30 AM

h3: ({ children }) => { const createUniqueRef = contentText .toLowerCase() .split(" ") .join("_"); return ( <h3 id={createUniqueRef}> <span>{children}</span> </h3> ); },

@vinnycodes

@vinnycodes
Copy link

Yep. I'm considering creating a similar work around. Possibly using "class" feature and then check if it starts with an octothorp.
I still think this is worth a feature request as it is a standard for modern development and it creates unnecessary coding edits /fragments for what should be common practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants