Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

UXPLATFORM-10247 - Fix onSelect not triggering for draggable items #4058

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions packages/terra-core-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Updated
* Updated terra list examples.
* Changed
* Updated documentation for `terra-form-select`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ListDraggableExample = () => {

const [dataList, setDataList] = useState(mockData);
const [selectedKey, setselectedKey] = useState('unique-0');
const [selectedData, setSelectedData] = useState('John Smith');
const listNode = useRef(null);

const reorderListItems = (list, startIndex, endIndex) => {
Expand All @@ -51,6 +52,7 @@ const ListDraggableExample = () => {
event.preventDefault();
if (selectedKey !== metaData.key) {
setselectedKey(metaData.key);
setSelectedData(metaData.data);
}
};

Expand All @@ -59,7 +61,7 @@ const ListDraggableExample = () => {
key={itemData.key}
isSelectable
isSelected={selectedKey === itemData.key}
metaData={{ key: itemData.key }}
metaData={{ key: itemData.key, data: itemData.title }}
onSelect={handleItemSelection}
>
<Placeholder title={itemData.title} className={cx('placeholder')} />
Expand All @@ -72,6 +74,9 @@ const ListDraggableExample = () => {
<>
<p id="list-help">
Select a patient from the list to view patient details.
Selected Item:
{' '}
{selectedData}
</p>
<List role="listbox" ariaDescribedBy="list-help" aria-label="list of patient" isDraggable onDragEnd={handleDragAndDrop} refCallback={(node) => handleRef(node)}>
{createListItems(dataList)}
Expand Down
3 changes: 3 additions & 0 deletions packages/terra-list/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Fixed
* Fixed `onSelect` not triggering when draggable item is clicked.

## 4.73.0 - (March 8, 2024)

* Fixed
Expand Down
9 changes: 6 additions & 3 deletions packages/terra-list/src/ListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ const ListItem = ({
attrSpread.onMouseDown = ListUtils.wrappedEventCallback(onMouseDown, event => event.currentTarget.setAttribute('data-item-show-focus', 'false'));
}
if (isDraggable) {
attrSpread.onClick = (event) => {
event?.currentTarget?.focus();
};
if (!onSelect) {
attrSpread.onClick = (event) => {
event?.currentTarget?.focus();
saket2403 marked this conversation as resolved.
Show resolved Hide resolved
return onClick;
};
}
attrSpread['aria-describedby'] = responseId;
}

Expand Down
1 change: 1 addition & 0 deletions packages/terra-list/src/ListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const wrappedOnClickForItem = (onClick, onSelect, metaData) => {
return onClick;
}
return (event) => {
event?.currentTarget?.focus();
onSelect(event, metaData);

if (onClick) {
Expand Down
Loading