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

inner text not updating when new value passed in #4

Open
4m2c4bl3 opened this issue Dec 17, 2019 · 4 comments
Open

inner text not updating when new value passed in #4

4m2c4bl3 opened this issue Dec 17, 2019 · 4 comments

Comments

@4m2c4bl3
Copy link

There seems to be an issue where the value inside the ellipsis is not updating when the text is long enough to be truncated.
Here's a demo:
https://codesandbox.io/s/demo-middle-ellipsis-l8wq1

@bluepeter
Copy link
Owner

What browser? It appears ellipsed for me in Chrome?

screenshot-codesandbox io-2019 12

@4m2c4bl3
Copy link
Author

4m2c4bl3 commented Dec 17, 2019

Try changing the text in the input to a shorter text, you'll see the value does not change.
I'm using the latest version of Chrome in Ubuntu.
image

To work around this behavior, I'm giving the MiddleEllipsis component a key based off the input value, which forces it to re-render.

@bluepeter
Copy link
Owner

I see... yeah, that looks to be a problem. Possibly related to #2

@axeldouglas
Copy link

axeldouglas commented Mar 10, 2021

Putting the children as useCallback prop:

measuredParent = useCallback(node => {
    if (node !== null) {
        window.addEventListener("resize", () => prepEllipse(node));
        prepEllipse(node);
        return () => window.removeEventListener("resize", () => prepEllipse(node));
    }
}, [props.children]);

And removing this if:

// (Re)-set text back to data-original-text if it exists.
if (txtToEllipse.hasAttribute('data-original')) {
    txtToEllipse.textContent = txtToEllipse.getAttribute( 'data-original');
}

Worked for me.

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

No branches or pull requests

3 participants