Skip to content

Commit

Permalink
ENH Use li for multi links
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Mar 13, 2024
1 parent 746cb83 commit 47dcb0c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions client/src/components/LinkField/LinkField.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,14 @@ const LinkField = ({
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
>
<SortableContext
items={linkIDs}
strategy={verticalListSortingStrategy}
>
{links}
</SortableContext>
<ul className="link-picker__list">
<SortableContext
items={linkIDs}
strategy={verticalListSortingStrategy}
>
{links}
</SortableContext>
</ul>
</DndContext>
</div>
}
Expand Down Expand Up @@ -476,6 +478,7 @@ const LinkField = ({
isKeyboardEditing={isKeyboardEditing}
/> }
{sortableLinks()}
{ /* This <LinkModalContainer> is only used for editing EXISTING links */ }
{ renderModal && <LinkModalContainer
types={types}
typeKey={data[editingID]?.typeKey}
Expand Down
1 change: 1 addition & 0 deletions client/src/components/LinkField/LinkField.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
box-shadow: none;
}
}

1 change: 1 addition & 0 deletions client/src/components/LinkPicker/LinkPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const LinkPicker = ({
onSelect={handleSelect}
onKeyDownEdit={onKeyDownEdit}
/>
{ /* This <LinkModalContainer> is only used for editing NEW links */ }
{ shouldOpenModal && <LinkModalContainer
types={types}
typeKey={typeKey}
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/LinkPicker/LinkPicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
}
}

.link-picker__list {
padding-left: 0;
}

.link-picker__drag-handle {
left: 5px;
position: absolute;
Expand Down
18 changes: 9 additions & 9 deletions client/src/components/LinkPicker/LinkPickerTitle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import classnames from 'classnames';
import i18n from 'i18n';
import React, { useContext } from 'react';
import React, { useContext, useState } from 'react';
import PropTypes from 'prop-types';
import { LinkFieldContext } from 'components/LinkField/LinkField';
import { Button } from 'reactstrap';
Expand Down Expand Up @@ -61,6 +61,7 @@ const LinkPickerTitle = ({
transform,
transition,
} = useSortable({id});
const [dragHandleToggled, setDragHandleToggled] = useState(false);

const handleButtonKeyDown = (event) => {
// Prevent the triggering the parent's keyboard sorting handler
Expand All @@ -82,13 +83,11 @@ const LinkPickerTitle = ({
event.preventDefault();
};

const handleIconKeyDown = (event) => {
const handleDragHandleKeyDown = (event) => {
if (!['Enter', 'Space'].includes(event.code)) {
return;
}
const el = event.target;
const newVal = el.getAttribute('aria-pressed') === 'true' ? 'false' : 'true';
el.setAttribute('aria-pressed', newVal);
setDragHandleToggled(!dragHandleToggled);
};

const style = {
Expand Down Expand Up @@ -119,7 +118,8 @@ const LinkPickerTitle = ({
// add this to the drag handle instead
delete attributes.tabIndex;
const idAttr = `link-picker__link-${id}`;
return <div
const Tag = isMulti ? 'li' : 'div';
return <Tag
className={className}
ref={setNodeRef}
style={style}
Expand All @@ -130,10 +130,10 @@ const LinkPickerTitle = ({
{ (isMulti && !readonly && !disabled) && <div className="link-picker__drag-handle"
tabIndex="0"
role="button"
aria-pressed="false"
aria-pressed={dragHandleToggled ? 'true' : 'false'}
aria-controls={idAttr}
aria-label="Sort Links"
onKeyDown={handleIconKeyDown}
onKeyDown={handleDragHandleKeyDown}
>
<i
className="font-icon-drag-handle"
Expand Down Expand Up @@ -173,7 +173,7 @@ const LinkPickerTitle = ({
>{deleteText}</span>
}
</Button>
</div>
</Tag>
};

LinkPickerTitle.propTypes = {
Expand Down

0 comments on commit 47dcb0c

Please sign in to comment.