Skip to content

Commit 8c31818

Browse files
fix(AnalyticalTable): don't select row when an actionable element was clicked (#432)
Closes #428
1 parent 5a4a083 commit 8c31818

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/main/src/components/AnalyticalTable/hooks/useSingleRowStateSelection.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,34 @@ const getRowProps = (rowProps, { row }) => {
1818
];
1919
};
2020

21+
const tagNamesWhichShouldNotSelectARow = new Set([
22+
'UI5-INPUT',
23+
'UI5-LINK',
24+
'UI5-BUTTON',
25+
'UI5-CHECKBOX',
26+
'UI5-COMBOBOX',
27+
'UI5-DATEPICKER',
28+
'UI5-MULTI-COMBOBOX',
29+
'UI5-SELECT',
30+
'UI5-RADIOBUTTON',
31+
'UI5-SEGMENTEDBUTTON',
32+
'UI5-SWITCH',
33+
'UI5-TOGGLEBUTTON'
34+
]);
35+
2136
const useInstance = (instance) => {
2237
const { webComponentsReactProperties, dispatch, toggleRowSelected, selectedFlatRows } = instance;
2338
const { isTreeTable, selectionMode, onRowSelected, selectionBehavior } = webComponentsReactProperties;
2439

2540
const selectSingleRow = useCallback(
2641
(row, e, selectionCellClick = false) => {
42+
if (
43+
tagNamesWhichShouldNotSelectARow.has(e.target.tagName) &&
44+
!(e.markerAllowTableRowSelection === true || e.nativeEvent?.markerAllowTableRowSelection === true)
45+
) {
46+
return;
47+
}
48+
2749
const isEmptyRow = row.original?.emptyRow;
2850
if ([TableSelectionMode.SINGLE_SELECT, TableSelectionMode.MULTI_SELECT].includes(selectionMode) && !isEmptyRow) {
2951
if (row.isGrouped || (TableSelectionBehavior.ROW_SELECTOR === selectionBehavior && !selectionCellClick)) {

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ export interface TableProps extends CommonProps {
122122
const useStyles = createComponentStyles(styles, { name: 'AnalyticalTable' });
123123

124124
/**
125-
* <code>import { AnalyticalTable } from '@ui5/webcomponents-react/lib/AnalyticalTable';</code>
125+
* <code>import { AnalyticalTable } from '@ui5/webcomponents-react/lib/AnalyticalTable';</code><br />
126+
* <br />
127+
* ### Usage Notes
128+
* By default, the `AnalyticalTable` will not select any rows after clicking on active elements like a `Button`, `Link`,
129+
* etc. <br />
130+
* In case you want to select the row anyways, you can "mark" the event to allow such a behaviour. <br />
131+
* Example: `<Link onClick={(e) => {e.markerAllowTableRowSelection = true;}>My Link Text</Link>`
126132
*/
127133
const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<HTMLDivElement>) => {
128134
const {

0 commit comments

Comments
 (0)