-
Notifications
You must be signed in to change notification settings - Fork 219
open and showModal are missing for dialog #822
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
Comments
@jquesada2016 can you point to the relevant documentation? |
Is this good enough? |
I agree that being able to control this via property would be much more pleasant to deal with, I think it'll need special support in |
I believe we would definitely need a |
Ah whoops, of course. What I meant then is I think |
Yes! Exactly right. Setting the |
Till it's implemented, can please someone tell how to call render :: ButtonState -> H.ComponentHTML ButtonAction () m
render _ = HH.dialog [HP.style "padding: 0"]
[HH.form [HP.style "padding: 1rem", methodDialog]
[HH.button_ [HH.text "X"]]]
where
-- "dialog" value isn't implemented yet, there's a PR
methodDialog = HH.attr (AttrName "method") "dialog" but how do I combine this halogen-purescript element with the |
Anyway, I couldn't find any way to integrate FFI into Halogen, so I presume the way you're supposed to work with that is by moving both component search and work on it to an FFI element as follows:
"use strict";
// See: https://github.com/purescript-halogen/purescript-halogen/issues/822
export const showModal = function(query) {
let n = document.querySelector(query);
if (n) {
n.showModal();
return true;
}
return false;
};
module FFI where
import Effect (Effect)
foreign import showModal :: String -> Effect Boolean And then adding a import FFI (showModal)
…
render _ = HH.dialog [HP.style "padding: 0", HP.id "mymodal"]
…
handleQuery (SetEnabled next) = do
_ <- H.liftEffect $ showModal "#mymodal"
… |
@Hi-Angel "officially" you are supposed to use refs. Here is a demo https://github.com/flip111/halogen-focus/blob/main/src/Main.purs#L58 |
So, I tried adding it and looking at the generated Also, isn't it the same as what I'm doing by creating a |
Okay, so, answering both questions:
The So my answer above becomes:
"use strict";
// See: https://github.com/purescript-halogen/purescript-halogen/issues/822
export const showModal = function(elem) {
elem.showModal();
};
module FFI where
import Prelude (Unit)
import Effect (Effect)
import Web.HTML.HTMLElement
foreign import showModal :: HTMLElement -> Effect Unit and in the component code: import FFI (showModal)
…
focusRef :: H.RefLabel
focusRef = H.RefLabel "mymodal"
…
render _ = HH.dialog [HP.style "padding: 0", HP.ref focusRef]
…
handleQuery (SetEnabled next) = do
H.getHTMLElementRef focusRef >>= traverse_ \elem -> H.liftEffect $ showModal elem
…
Right. Well, the only difference is that the check for whether search succeeded moves to inside PureScript, but other than that there's no difference. |
There are two separate issues here
You can make your FFI function something like
It's done by holding a reference to the value AFAIK not through attributes directly on the DOM level.
There isn't much difference in my opinion as well. Refs are supposed to give you more type safety and assurance that the element is there. Opposed to having a type in your css query selection or something removed the element from the dom and now things start to crash I wrote all that before i read your second post, i see you figured it out :D |
Seems to be some ffi definition mistakes? "use strict";
// See: https://github.com/purescript-halogen/purescript-halogen/issues/822
export const showModal = function(elem) {
return function () {
elem.showModal();
};
}; |
Oh, so that's why I was getting a weird |
Using refs is indeed not really that much different than using DOM methods like There's also that |
I saw that diallog had an open row in it's attribute row type. However, I don't see any functions to create the open attribute for the dialog element.
Also, showModal would be a great addition, although it is neither a property nor an attribute, as per the spec, but it might not be a bad idea to add it as a helper prop where the VDom can call .showModal() and .close() on the element as the prop is added/removed.
The text was updated successfully, but these errors were encountered: