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 option to return an HTMLElement from the icon helper #3126

Merged
merged 5 commits into from
Nov 8, 2023

Conversation

LuomaJuha
Copy link
Contributor

Sometimes it is easier to manipulate the icon when it is an HTMLElement like when assigining it into a value, so here is a small adjustment for the icon function.

@demiankatz
Copy link
Member

Thanks, @LuomaJuha! I'd like to get @crhallberg's opinion on this, since I believe he wrote most of the original code that's impacted. He's going to be on vacation for the next week or so, but hopefully he can look at it when he returns if he can't get to it before he leaves tomorrow. :-)

Copy link
Contributor

@crhallberg crhallberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comments are nitpicks. This looks very good and I like the direction!

const oldAttrs = _element.getAttribute(key);
if (oldAttrs !== null) {
newAttrs = [...newAttrs, ...oldAttrs.split(" ")];
// Remove duplicate values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use a Set to remove duplicate values as you compile them.

const newAttrsSet = new Set([...newAttrs, ...oldAttrs.split(" ")]);
//...
_element.setAttribute(key, Array.from(newAttrsSet).join(" "));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other attributes that require space separated strings other than class? If we're going to be working on an Element directly, I'd like Element to do as much work as possible. This actually makes me think we should be overriding the attributes instead of appending them (except for class). I know this is based on my code but I've since learned how complicated this can get.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I would think that class could be the only one, only if there is some custom datasets but otherwise shouldn't be, ill try and adjust

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crhallberg made some small changes where if the key is not class then just sets it instantly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @LuomaJuha! @crhallberg, do you mind taking another look at this when you have a chance?

@demiankatz demiankatz requested a review from crhallberg October 16, 2023 13:05
@demiankatz demiankatz added this to the 10.0 milestone Oct 16, 2023
@demiankatz
Copy link
Member

I suspect we'll be able to merge this soon, but since things are getting locked down for 9.1, it will probably have to wait for release 10.0. I'm setting a milestone to be sure we don't lose track of it.

Copy link
Contributor

@crhallberg crhallberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making those changes! I was thinking about using classList for this, but I think that would lead to more confusing code. Thank you!

@demiankatz demiankatz merged commit e1f0d8c into vufind-org:dev Nov 8, 2023
6 checks passed
@demiankatz
Copy link
Member

Thanks, @LuomaJuha and @crhallberg!

@LuomaJuha LuomaJuha deleted the adjust-icon-helper-function branch November 29, 2023 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants