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

Commit

Permalink
UXPLATFORM-10247 - Fix onSelect not triggering for draggable items (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
saket2403 authored Mar 12, 2024
1 parent 9ad0577 commit cb6d0eb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
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();
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

0 comments on commit cb6d0eb

Please sign in to comment.