Skip to content

Commit 3b5a2f5

Browse files
authored
fix(AnalyticalTable & FilterBar): fully support ui5-webcomponents scoping (#5537)
1 parent f5b23f8 commit 3b5a2f5

File tree

6 files changed

+36
-17
lines changed

6 files changed

+36
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ describe('AnalyticalTable', () => {
400400

401401
// column filter + select
402402
cy.findByText('Name').click();
403-
cy.get(`ui5-input[show-clear-icon]`).typeIntoUi5Input('Flowers Mcfarland', { force: true });
403+
cy.get(`[ui5-input][show-clear-icon]`).typeIntoUi5Input('Flowers Mcfarland', { force: true });
404404
cy.findByText('Robin Moreno').should('not.exist', { timeout: 100 });
405405
cy.findByText('Judith Mathews').should('not.exist', { timeout: 100 });
406406
cy.findByText('Katy Bradshaw').should('not.exist', { timeout: 100 });
@@ -675,7 +675,7 @@ describe('AnalyticalTable', () => {
675675

676676
cy.findByText('Friend Name').click();
677677
cy.findByText('Group').click();
678-
cy.get('[aria-rowindex="7"] > [aria-colindex="3"] > [title="Expand Node"] > ui5-icon').click();
678+
cy.get('[aria-rowindex="7"] > [aria-colindex="3"] > [title="Expand Node"] > [ui5-icon]').click();
679679

680680
cy.findByText('25').click();
681681
cy.get('@onRowSelectSpy').should('have.callCount', 2);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base';
22
import { AnalyticalTableSelectionBehavior, AnalyticalTableSelectionMode } from '../../../enums/index.js';
3+
import { getTagNameWithoutScopingSuffix } from '../../../internal/utils.js';
34
import type { ReactTableHooks } from '../types/index.js';
45

56
const getRowProps = (rowProps, { row, instance }) => {
@@ -9,7 +10,9 @@ const getRowProps = (rowProps, { row, instance }) => {
910
if (
1011
e.target?.dataset?.name !== 'internal_selection_column' &&
1112
!(e.markerAllowTableRowSelection === true || e.nativeEvent?.markerAllowTableRowSelection === true) &&
12-
webComponentsReactProperties.tagNamesWhichShouldNotSelectARow.has(e.target.tagName)
13+
webComponentsReactProperties.tagNamesWhichShouldNotSelectARow.has(
14+
getTagNameWithoutScopingSuffix(e.target.tagName)
15+
)
1316
) {
1417
return;
1518
}
@@ -59,7 +62,11 @@ const getRowProps = (rowProps, { row, instance }) => {
5962
(!e.target.hasAttribute('aria-expanded') || (e.shiftKey && e.code === 'Space')) &&
6063
(e.key === 'Enter' || e.code === 'Space')
6164
) {
62-
if (!webComponentsReactProperties.tagNamesWhichShouldNotSelectARow.has(e.target.tagName)) {
65+
if (
66+
!webComponentsReactProperties.tagNamesWhichShouldNotSelectARow.has(
67+
getTagNameWithoutScopingSuffix(e.target.tagName)
68+
)
69+
) {
6370
e.preventDefault();
6471
}
6572
handleRowSelect(e);

packages/main/src/components/FilterBar/FilterBar.cy.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ describe('FilterBar.cy.tsx', () => {
2929
);
3030

3131
cy.findByText('Classification').should('be.visible');
32-
cy.get('ui5-select').should('be.visible');
32+
cy.get('[ui5-select]').should('be.visible');
3333

3434
cy.findByText('Hide Filter Bar').click();
3535
cy.get('@toggleSpy').should('have.been.calledOnce');
3636

3737
cy.findByText('Classification').should('not.be.visible');
38-
cy.get('ui5-select').should('not.be.visible');
38+
cy.get('[ui5-select]').should('not.be.visible');
3939

4040
cy.findByText('Show Filter Bar').click();
4141
cy.get('@toggleSpy').should('have.been.calledTwice');
4242

4343
cy.findByText('Classification').should('be.visible');
44-
cy.get('ui5-select').should('be.visible');
44+
cy.get('[ui5-select]').should('be.visible');
4545

4646
cy.mount(
4747
<FilterBar onToggleFilters={toggle} hideToggleFiltersButton>
@@ -133,7 +133,7 @@ describe('FilterBar.cy.tsx', () => {
133133
cy.findByText('Show Values').click();
134134
}
135135

136-
const checkboxes = cy.get('ui5-checkbox');
136+
const checkboxes = cy.get('[ui5-checkbox]');
137137
// hidden select-all checkbox is also counted
138138
checkboxes.should('have.length', 4);
139139

@@ -244,7 +244,7 @@ describe('FilterBar.cy.tsx', () => {
244244
cy.findAllByText('SWITCH').should('have.length', 2);
245245
cy.findAllByText('SELECT').should('have.length', 1);
246246

247-
cy.findByPlaceholderText('Search for filters').shadow().find('ui5-icon').click();
247+
cy.findByPlaceholderText('Search for filters').shadow().find('[ui5-icon]').click();
248248

249249
cy.findAllByText('INPUT').should('have.length', 2);
250250
cy.findAllByText('SWITCH').should('have.length', 2);

packages/main/src/components/FilterBar/utils.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Ref } from 'react';
22
import { cloneElement } from 'react';
3+
import { getTagNameWithoutScopingSuffix } from '../../internal/utils.js';
34

45
const inputTagNames = new Set([
56
'UI5-COMBOBOX',
@@ -16,11 +17,13 @@ const inputTagNames = new Set([
1617

1718
export const filterValue = (ref, child) => {
1819
const tagName = ref.tagName;
20+
const tagNameWithoutSuffix = getTagNameWithoutScopingSuffix(tagName);
21+
1922
let filterItemProps = {};
20-
if (inputTagNames.has(tagName)) {
23+
if (inputTagNames.has(tagNameWithoutSuffix)) {
2124
filterItemProps = { value: ref.value ?? '' };
2225
}
23-
if (tagName === 'UI5-SELECT' || tagName === 'UI5-MULTI-COMBOBOX') {
26+
if (tagNameWithoutSuffix === 'UI5-SELECT' || tagNameWithoutSuffix === 'UI5-MULTI-COMBOBOX') {
2427
const selectedIndices = Array.from(ref.children as HTMLCollectionOf<any>)
2528
.map((item, index) => (item.selected ? index : false))
2629
.filter((el) => el !== false);
@@ -33,7 +36,7 @@ export const filterValue = (ref, child) => {
3336
});
3437
filterItemProps = { children: options };
3538
}
36-
if (tagName === 'UI5-SWITCH' || tagName === 'UI5-CHECKBOX') {
39+
if (tagNameWithoutSuffix === 'UI5-SWITCH' || tagNameWithoutSuffix === 'UI5-CHECKBOX') {
3740
filterItemProps = { checked: ref.checked };
3841
}
3942
return filterItemProps;

packages/main/src/components/VariantManagement/VariantManagement.cy.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ describe('VariantManagement', () => {
469469
author
470470
} = props;
471471

472-
cy.get(`ui5-table-row[data-id="${rowId}"]`).as('row');
472+
cy.get(`[ui5-table-row][data-id="${rowId}"]`).as('row');
473473
if (showOnlyFavorites) {
474474
if (labelReadOnly) {
475475
if (favorite || isDefault) {
@@ -480,18 +480,18 @@ describe('VariantManagement', () => {
480480
} else {
481481
if (favorite || isDefault) {
482482
cy.findAllByText(rowId).should('have.length', 1);
483-
cy.get('@row').find('ui5-input').findShadowInput().should('have.value', rowId);
483+
cy.get('@row').find('[ui5-input]').findShadowInput().should('have.value', rowId);
484484
} else {
485485
cy.findByText(rowId, { timeout: 100 }).should('not.exist');
486-
cy.get('@row').find('ui5-input').findShadowInput().should('have.value', rowId);
486+
cy.get('@row').find('[ui5-input]').findShadowInput().should('have.value', rowId);
487487
}
488488
}
489489
} else {
490490
if (labelReadOnly) {
491491
cy.findAllByText(rowId).should('have.length', 2);
492492
} else {
493493
cy.findAllByText(rowId).should('have.length', 1);
494-
cy.get('@row').find('ui5-input').findShadowInput().should('have.value', rowId);
494+
cy.get('@row').find('[ui5-input]').findShadowInput().should('have.value', rowId);
495495
}
496496
}
497497

packages/main/src/internal/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getEffectiveScopingSuffixForTag, getScopedVarName } from '@ui5/webcomponents-base/dist/CustomElementsScope.js';
1+
import {
2+
getCustomElementsScopingSuffix,
3+
getEffectiveScopingSuffixForTag,
4+
getScopedVarName
5+
} from '@ui5/webcomponents-base/dist/CustomElementsScope.js';
26
import type { ReactNode } from 'react';
37
import { Children, cloneElement, Fragment } from 'react';
48

@@ -46,3 +50,8 @@ export function trimAndRemoveSpaces(value) {
4650
}
4751

4852
export const cssVarVersionInfoPrefix = getScopedVarName('--_ui5_').replace('--_ui5_', '');
53+
54+
export function getTagNameWithoutScopingSuffix(tagName) {
55+
const tagNameSuffix = getCustomElementsScopingSuffix();
56+
return tagNameSuffix ? tagName.replace(`-${tagNameSuffix.toUpperCase()}`, '') : tagName;
57+
}

0 commit comments

Comments
 (0)