Skip to content

Commit c616e66

Browse files
committed
Merge branch 'picker-fixes' into trunk
2 parents 9e916e6 + 21e08c5 commit c616e66

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

components/ContentPicker/PickedItem.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { safeDecodeURI, filterURLForDisplay } from '@wordpress/url';
33
import { decodeEntities } from '@wordpress/html-entities';
44
import { __ } from '@wordpress/i18n';
55
import { useSelect } from '@wordpress/data';
6+
import { sortableHandle } from 'react-sortable-hoc';
67
/** @jsxImportSource @emotion/react */
78
import { jsx } from '@emotion/react'; // eslint-disable-line no-unused-vars
89

@@ -12,6 +13,9 @@ import { jsx } from '@emotion/react'; // eslint-disable-line no-unused-vars
1213
* @param {Object} props react props
1314
* @return {*} React JSX
1415
*/
16+
17+
const DragHandle = sortableHandle(() => <svg style={{ marginRight: '5px', cursor: 'grab' }} width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" role="img" aria-hidden="true" focusable="false"><path d="M5 4h2V2H5v2zm6-2v2h2V2h-2zm-6 8h2V8H5v2zm6 0h2V8h-2v2zm-6 6h2v-2H5v2zm6 0h2v-2h-2v2z"></path></svg>);
18+
1519
const PickedItem = ({ item, isOrderable, handleItemDelete, sortIndex, mode, totalItems }) => {
1620
const type = mode === 'post' ? 'postType' : 'taxonomy';
1721

@@ -34,18 +38,19 @@ const PickedItem = ({ item, isOrderable, handleItemDelete, sortIndex, mode, tota
3438

3539
return preparedItem ? (
3640
<div
37-
css={{
38-
cursor: isOrderable && totalItems > 1 ? 'move' : 'default',
41+
style={{
3942
border: '2px dashed #ddd',
40-
':hover': !isOrderable
41-
? {
42-
backgroundColor: 'transparent',
43-
}
44-
: '',
43+
paddingTop: '10px',
44+
paddingBottom: '10px',
45+
paddingLeft: isOrderable ? '3px' : '8px'
4546
}}
4647
className="block-editor-link-control__search-item is-entity"
4748
>
49+
{isOrderable ?
50+
<DragHandle />
51+
: '' }
4852
<span className="block-editor-link-control__search-item-header">
53+
4954
<span className="block-editor-link-control__search-item-title">
5055
{decodeEntities(preparedItem.title)}
5156
</span>

components/ContentPicker/SortableList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const SortableList = SortableContainer(({ items, isOrderable, handleItemDelete,
77
<div>
88
{items.map((item, index) => (
99
<ItemComponent
10-
isOrderable={isOrderable}
10+
isOrderable={isOrderable && items.length > 1 ? isOrderable : false}
1111
key={`item-${item.id}`}
1212
index={index}
1313
handleItemDelete={handleItemDelete}

components/ContentPicker/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,18 @@ const ContentPicker = ({
139139
const hasSearchString = !!searchString.length;
140140
const hasSearchResults = !!searchResults.length;
141141

142+
/**
143+
* Unfortunately, we had to use !important because on PickedItem we couldn't @emotion/styled css
144+
* as it was breaking sortability from react-sortable-hoc
145+
*/
142146
const StyleWrapper = styled('div')`
143147
& .block-editor-link-control__search-item {
144-
border: none;
148+
border: none !important;
149+
cursor: default;
150+
151+
&:hover {
152+
background: transparent;
153+
}
145154
}
146155
`;
147156

@@ -215,6 +224,7 @@ const ContentPicker = ({
215224

216225
<SortableList
217226
items={content}
227+
useDragHandle
218228
isOrderable={isOrderable}
219229
mode={mode}
220230
handleItemDelete={handleItemDelete}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "1.0.0",
6+
"version": "1.0.1",
77
"description": "10up Components built for the WordPress Block Editor.",
88
"main": "index.js",
99
"scripts": {

0 commit comments

Comments
 (0)