Proposal: hx-drag
hx-drop
attributes for more complicated drag-drop interactions
#3132
Closed
AjaniBilby
started this conversation in
Ideas
Replies: 2 comments
-
Didn't check the code at all yet, just to let you know that if you are interested, feel free to create a repository of your own to host such an extension, and open a PR on this repo to add it to our community extensions list! |
Beta Was this translation helpful? Give feedback.
0 replies
-
I wasn't sure if it's really a good idea, but I've slept on it and expanded my example a lot. |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
Currently there is the ability to do some simple drag and drop behaviour as seen in the sorting example. However this relies on information all being contained within one form, and doesn't account for being able to drag and drop elements from completely different parts of the DOM for certain interfaces.
I propose that a new htmx extension should be added which would include the official addition of
hx-drag
andhx-drop
attributes.hx-drag
is the data added to the request headers when the eventual drop is producedhx-drop
is thehref
where the request will be submitted (by default withPUT
)hx-drop-method
overrides what method the drop request will be sent with.Example Scenario
With just the addition of these two attributes you can make drag-drop based UIs, where each of the
PUT
requests can simply reply with aHX-Location:
(meaning "", i.e. current href) triggering a reload of the page usinghx-boost
if present.You could also use an oob update to only replace the changed elements instead of reloading the whole page, but that could get a lot more complex quicky, and leave to a corrupt state in the page.
Sample Implementation
Since this doesn't rely on anything from htmx other than it being pre-loaded into global scope, technically this does not need to be an official extension, however since it does carve out a part of the available
hx-
namespace I figured I should ask about it here. Plus maybe someone more experienced than me might have some reason why this could be a bad idea, or how it could be improved.Beta Was this translation helpful? Give feedback.
All reactions