Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

feat: drag n drop component 483 #747

Merged
merged 25 commits into from
Jan 30, 2020
Merged

Conversation

pr3tori4n
Copy link
Contributor

Related Issue: #483

Summary

  • Adds new calcite-sortable-list component, which can accept a list of any DOM nodes that can be sorted, so long as they have a handle with the same class as what's provided to the list (defaults to .handle).
  • Adds calcite-handle component, which is a button that has the drag icon. This element has an activated prop which toggles based on if it's selected via keyboard, and fires a custom event when the up and down arrow keys are pressed when focused on the element.
  • The list listens to the custom events fired by the handle to know when to trigger keyboard sorting.
  • The block component was modified to add the drag-handle boolean prop, which adds a calcite-handle to the heading area when true. False by default.

@pr3tori4n pr3tori4n requested a review from a team as a code owner January 9, 2020 22:47
@pr3tori4n pr3tori4n self-assigned this Jan 9, 2020
@pr3tori4n pr3tori4n requested review from jcfranco and driskull January 9, 2020 22:47
@pr3tori4n pr3tori4n added the new component New component request label Jan 9, 2020
@pr3tori4n pr3tori4n added this to the Grob Gob Glob Grod milestone Jan 9, 2020
Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

Had some comments but looking good

* Emmitted when the the handle is activated and the up or down arrow key is pressed.
* @event calciteHandleNudge
*/
@Event() calciteHandleNudge: EventEmitter;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call this calciteHandleMove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm...you're not really moving the handle right you're moving the parent. @franco thoughts? I'm def open to renaming tho its a meh name.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we don't need this event and the keydown logic can just be added on the parent?

Copy link
Member

Choose a reason for hiding this comment

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

If we do keep the event(s), let's make it based on whether it should be moved ahead or behind in the list instead of using direction like up/down/left/right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's cleaner with the event, otherwise the event handler gets a bit messy when trying to find the handler in the composedPath.

Copy link
Member

Choose a reason for hiding this comment

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

Leaving as up/down for now. We can add other directions in the future.


render() {
return (
<button
Copy link
Member

Choose a reason for hiding this comment

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

Does it not need a host?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't seem necessary. The :host selector is still applied to the tag. I think you only need it if you either need the parent wrapper or if you need to modify its attributes.

@pr3tori4n pr3tori4n requested a review from driskull January 17, 2020 21:46
Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

Looking good

* Emmitted when the the handle is activated and the up or down arrow key is pressed.
* @event calciteHandleNudge
*/
@Event() calciteHandleNudge: EventEmitter;
Copy link
Member

Choose a reason for hiding this comment

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

If we do keep the event(s), let's make it based on whether it should be moved ahead or behind in the list instead of using direction like up/down/left/right.

@pr3tori4n pr3tori4n requested a review from driskull January 22, 2020 18:47
Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

comments

Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

👍

/**
* The class on the handle elements.
*/
@Prop() handleSelector = ".handle";
Copy link
Member

Choose a reason for hiding this comment

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

So is the .handle going into the shadowDom and the drag and drop supports it? Just wondering why it isn't just calcite-handle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the host can't receive focus, its basically a div. The button is the focus item and the cornerstone of the handle functionality. When using the keyboard, when sortable sorts the items, the parent of the handle will be removed from the dom and re-inserted. This causes it to lose focus so we have to re-apply focus. That focus needs to go on the button, not the host.

Copy link
Member

Choose a reason for hiding this comment

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

@pr3tori4n does Sortable find the .handle in the shadowDOM? Is that how this works?

Copy link
Member

Choose a reason for hiding this comment

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

fixme: Lets change this to calcite-handle by default with the setFocus() method.

Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

Lets change the handle to have a setFocus() method similar to the calcite-action to handle focusing internally.

this.items = Array.from(this.el.children);

event.detail.handle.activated = true;
event.detail.handle.shadowRoot.querySelector(this.handleSelector).focus();
Copy link
Member

Choose a reason for hiding this comment

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

fixme: I think we should add a setFocus() method on the handle instead of going through the shadowRoot. We already do this for the calcite-action and calcite-panel

Copy link
Member

Choose a reason for hiding this comment

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

@pr3tori4n this wouldn't work in Edge anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should now that Edge is on Chromium shouldn't it?

Copy link
Member

Choose a reason for hiding this comment

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

It should now that Edge is on Chromium shouldn't it?

We should support older edge users regardless.

/**
* The class on the handle elements.
*/
@Prop() handleSelector = ".handle";
Copy link
Member

Choose a reason for hiding this comment

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

fixme: Lets change this to calcite-handle by default with the setFocus() method.

@pr3tori4n pr3tori4n requested a review from driskull January 30, 2020 20:18
Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

Just some questions on typings.


@State() handleActivated = false;

items: Element[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

question: should this be HTMLElement? since its coming chiildren of HTMLElement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changing this causes a TS error on lines this.items = Array.from(this.el.children);

@pr3tori4n pr3tori4n merged commit 71d5897 into master Jan 30, 2020
@pr3tori4n pr3tori4n deleted the hrobbins/drag-n-drop-component-483 branch January 30, 2020 22:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new component New component request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants