Skip to content
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

List: Sortable list interactions update #1541

Merged
merged 15 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/app/views/examples/components/list/_preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ that will be called after the user finishes sorting an item.
} %>

<h3 class="<%= SageClassnames::TYPE::HEADING_6 %>">Fully draggable row</h3>
<%= md("
<%= md('
By default only the drag handle is active for dragging/sorting a row.
However, `draggable_anywhere` can be set to `true` in order to allow the whole row to be draggable instead.
", use_sage_type: true) %>
However, `drag_handle_type` can be set to `"row"` in order to allow the whole row to be draggable instead.
', use_sage_type: true) %>

<%= sage_component SageList, {
sortable: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<%
tag = component.tag.present? ? component.tag : "ul"
drag_handle_type = component.tag.present? ? component.tag : "default"
tag = component.sortable ? "ol" : "ul"
if component.tag.present?
ju-Skinner marked this conversation as resolved.
Show resolved Hide resolved
tag = component.tag
end
drag_handle_type = component.drag_handle_type.present? ? component.drag_handle_type : "default"
%>
<<%= tag %>
class="
sage-list
<%= component.generated_css_classes %>
<%= "sage-list--sortable" if component.sortable %>
<%= "sage-list--draggable-by-row" if component.drag_handle_type == "row" %>
<%= "sage-list--draggable-by-row" if drag_handle_type == "row" %>
"
<%= "data-js-list-sortable=#{component.sortable_resource}" if component.sortable_resource.present? %>
<%= component.generated_html_attributes.html_safe %>
Expand Down
15 changes: 9 additions & 6 deletions packages/sage-react/lib/List/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const List = ({
);
};

const Tag = tag;
let Tag = sortable ? 'ol' : 'ul';
if (tag) {
Tag = tag;
}

return sortable ? (
<ReactSortable
Expand Down Expand Up @@ -91,13 +94,13 @@ List.defaultProps = {
children: null,
className: null,
items: [],
itemRenderer: null,
itemRenderer: () => null,
dragHandleType: List.DRAG_HANDLE_TYPES.DEFAULT,
onEnd: null,
onStart: null,
setList: null,
onEnd: () => null,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is the equivalent to what you had before...you can do one of two things

  1. () => {} // returns undefined <- this is common
  2. () => ( undefined ) // explicitly returns undefined

onStart: () => null,
setList: () => [],
sortable: false,
tag: 'ul',
tag: null,
};

List.propTypes = {
Expand Down