Code Monkey home page Code Monkey logo

sortable-list's Introduction

License Published on webcomponents.org

Demo and API docs

GIF

sortable-list

sortable-list is a custom element that allows you to sort an element from a list by dragging it.

<sortable-list on-sort-finish="_onSortFinish" dragging="{{dragging}}">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</sortable-list>

...
onSortFinish(event) {
  const sortedItem = event.detail.target;
}

When using a dom-repeat you must specify which items are sortable.

<sortable-list sortable=".item">
  <dom-repeat>
    <div class="item"></div>
  </dom-repeat>
</sortable-list>

TODO:

  • Allow sort of elements with different sizes #2

sortable-list's People

Contributors

basvanbeek avatar pdgago avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sortable-list's Issues

Can't use flexbox with the list items

Since the list of items are inside the <div id="items"></div> container, we can't set a flexbox container on <sortable-list>. This is great use case for a custom css mixin.

Order of elements not updating on change items

Code:

<sortable-list class="items-sortable" on-sort-finish="_onSortFinish" dragging="{{dragging}}"
          sortable=".item" items="{{someItemsSorted}}">
  <template is="dom-repeat" items="[[itemsUpdatableFromApi]]">
    <div class="item"> ....
  ...
...

This issue is that when itemsUpdatableFromApi variable is changing, and the order of them changed, the order of items in component keep not changed. However, the data in items is updating correctly.

To clarify the issue I will describe steps:

  1. Items in sortable-list:
<div id="51">1</div>
<div id="52">2</div>
<div id="53">3</div>
  1. Move item with id 53 up:
<div id="51">1</div>
<div id="53">3</div>
<div id="52">2</div>
  1. Send API request on on-sort-finish to change the priorities (sort order)
  2. Update the items (in code above we just change the property itemsUpdatableFromApi with data, fetched from API)
<div id="51">1</div>
<div id="52">3</div>
<div id="53">2</div>

So, the id is changed and this is the correct data, but the order of displaying should be changed too. Because from API I receive items correctly ordered by priority (1,2,3)). But when I refresh the page, the order of items is correct:

<div id="51">1</div>
<div id="53">2</div>
<div id="52">3</div>

Cannot scroll the list in mobile when disabled

By default, items in the list cannot be scrolled in mobile even though sortable-list is disabled! I found a way around by calling the _toggleListeners(false) inside sortable-list component which stops adding the event listeners. That makes the list scrollable in mobile!
If I _toggleListener(true), It adds the event listeners and makes the list sortable. But now if I call the _toggleListner(false) again with "false", it does removes the event listeners but list is not scrollable anymore.
Help would be much appreciated. thanks

items rendered outside container and popup

I have my sortable list in a container element with overflow-y:auto, and it is inside a paper-dialog, and I notice that items are rendered outside their container and popup when they are being dragged.

I wonder if this is related to:

#9

draggable sometimes not removed

I've been using this element for some time, and it generally works as advertised, but sometimes it seems to duplicate the item being dropped, adding to the list. It seems like the item being dragged isn't removed, so there is the original item still there, and a new one in the new position with a class 'draggable'. If I manually remove the original item in a 'sort-end' handler, then it seems to work fine.

Does this ring any bells? Any ideas for a 'real' fix?

TBH, I seem to have copied the element code, so I'm not sure what version I'm using - the source code has no record of the version. Is there a way to find out what version it is? I don't think I've changed it in any way.

[Feature Request] Scroll support

First of all, a big thanks for all the work done in this web component. While on mobile, its hard to sort a medium size list of items because of the limited size of the screen, can we add an auto scrolling functionality? I've been working something out, and i'll be glad to make a pull request.

Doesn't work when in a transformed element

I've tried using sortable-list within an element that has been transformed (to be honest, just rotateZ(0)). This causes the width & height of the elements when dragging to be wrong by the difference between the top of the window and the sortable list.

sortable-list:
 -------------
|      first element (should be at top left)
|     -----------
|     |               |

new minor release

Just noticed the last updates in master are not tagged with a release version yet.

Can you bump the minor version?

[ASK] Disable position of disabled sortable item

Can we disable the position of disabled sortable item using this component? For example I have this snippet:

<sortable-list sortable=".mcItem" id="mcList" on-items-changed="itemsOrder">
  <paper-item class="mcItem" value="[[dataMcTrendCross.rows.0.id]]" disabled="true">
    <div class="col m10">[[dataMcTrendCross.rows.0.MenuCategory.name]]</div>
  </paper-item>
  <template is="dom-repeat" items="[[dataMc.rows]]" as="mc">
    <paper-item class="mcItem" value="[[mc.id]]">
      <div class="col m10">[[mc.MenuCategory.name]]</div>
      <div class="col m2">
        <paper-icon-button icon="delete" id="[[mc.id]]" on-click="deleteMc" value="[[mc.id]]"></paper-icon-button>
      </div>
    </paper-item>
  </template>
  <paper-item class="mcItem" value="[[dataMcTrendCross.rows.1.id]]" disabled="true">
    <div class="col m10">[[dataMcTrendCross.rows.1.MenuCategory.name]]</div>
  </paper-item>
</sortable-list>

On that code, I already disabled the first and the last paper-items so those can't be dragged. But somehow the other paper-items inside the dom-repeat still can be dragged and replace the disabled paper-items position. How would I disable the position of the disabled paper-items so another active paper-items can't replace their position?

Demo does not work

When I viewed the demo in Safari nothing rendered within the demo page aside from the header "Drag the Items". In chrome I can see the animal images but am unable to drag them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.