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

API idea: `contains` predicate on Json.Decode.Value #868

Closed
97jaz opened this Issue May 17, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@97jaz

97jaz commented May 17, 2017

A fairly common need when creating various kinds of menus is to be able to determine, when receiving a blur or focusout event on your menu's outermost element, whether focus has shifted to a descendant of that element (in which case you want to keep the menu open) or not (in which case you want to close the menu).

There are a number of ways to accomplish the same goal, but the most straightforward way I know of -- though I could be overlooking something -- is to ask whether the relatedTarget of a focusout event is a descendant of the target. I don't know of a way to do this in Elm today without using a Native module.

It looks like it should be very simple [see update below] to wrap the DOM's Node.contains method as a function on Json.Decode.Values so that it could be used in decoders.

I'd be happy to put together a PR, but I figured I should check first to see whether there's a better way to accomplish the same goal or, even if there isn't, this idea doesn't appeal to the maintainers.

Update: sorry, I should have thought about this a bit longer before posting it. The contains predicate only makes sense on DOM nodes, not on Values generally. My initial thought is that DOM events need a richer representation in Elm. But given the current representation, the simplest -- though not very appealing -- way to handle this would be to offer a function with a type like: Value -> Maybe Node, but it's... hard to like that.

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot May 17, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented May 17, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@97jaz

This comment has been minimized.

Show comment
Hide comment
@97jaz

97jaz May 17, 2017

I see that the checklist page says that issues are for bugs, so maybe this doesn't belong here? I created this after reading the text in #322 that says "Open a separate issue for your particular idea." So... I'm not sure if this belongs here or not.

97jaz commented May 17, 2017

I see that the checklist page says that issues are for bugs, so maybe this doesn't belong here? I created this after reading the text in #322 that says "Open a separate issue for your particular idea." So... I'm not sure if this belongs here or not.

@97jaz

This comment has been minimized.

Show comment
Hide comment
@97jaz

97jaz May 17, 2017

As this is no longer a concrete API idea, I'm just going to close it.

97jaz commented May 17, 2017

As this is no longer a concrete API idea, I'm just going to close it.

@97jaz 97jaz closed this May 17, 2017

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