Skip to content

Commit 376f9c1

Browse files
feat(All Components): Allow all HTML events to be passed (#370)
As the events are not part of the typings you have to use ts-ignore in case you are using TypeScript.
1 parent 338b8b3 commit 376f9c1

File tree

10 files changed

+27
-61
lines changed

10 files changed

+27
-61
lines changed

packages/base/src/hooks/usePassThroughHtmlProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from 'react';
22

3-
const PROP_WHITELIST = /^(aria-|data-|id$)/;
3+
const PROP_WHITELIST = /^(aria-|data-|id$|on[A-Z])/;
44

55
export const usePassThroughHtmlProps = (props) => {
66
const passThroughPropNames = Object.keys(props).filter((name) => PROP_WHITELIST.test(name));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ export const AnalyticalCardHeader: FC<AnalyticalCardHeaderPropTypes> = forwardRe
128128
return (
129129
<div
130130
ref={ref}
131-
onClick={onClick}
132131
className={headerClasses.valueOf()}
133132
title={tooltip}
134133
style={style}
135134
{...passThroughProps}
135+
onClick={onClick}
136136
>
137137
<div className={classes.headerContent}>
138138
<div className={classes.headerTitles}>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ const Avatar: FC<AvatarPropTypes> = forwardRef((props: AvatarPropTypes, ref: Ref
9191
ref={ref}
9292
className={cssClasses.join(' ')}
9393
style={inlineStyle}
94-
onClick={handleOnClick}
9594
tabIndex={0}
96-
onKeyDown={handleKeyDown}
9795
title={tooltip}
9896
slot={slot}
9997
{...passThroughProps}
98+
onClick={handleOnClick}
99+
onKeyDown={handleKeyDown}
100100
>
101101
{initials ? initials : children}
102102
</span>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,20 @@ const Carousel: FC<CarouselPropTypes> = forwardRef((props: CarouselPropTypes, re
170170
ref={ref}
171171
role="list"
172172
tabIndex={0}
173-
onKeyDown={onKeyDown}
174173
{...passThroughProps}
174+
onKeyDown={onKeyDown}
175175
>
176176
{childElementCount > 1 && pageIndicatorPlacement === PlacementType.Top && (
177177
<CarouselPagination
178178
arrowsPlacement={arrowsPlacement}
179179
showPageIndicator={showPageIndicator}
180180
pageIndicatorPlacement={pageIndicatorPlacement}
181181
activePage={currentlyActivePage}
182-
children={children}
183182
goToPreviousPage={goToPreviousPage}
184183
goToNextPage={goToNextPage}
185-
/>
184+
>
185+
{children}
186+
</CarouselPagination>
186187
)}
187188
<div
188189
className={classes.carouselInner}

packages/main/src/components/FlexBox/FlexBox.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mount } from 'enzyme';
33
import { FlexBox } from '@ui5/webcomponents-react/lib/FlexBox';
44
import { FlexBoxJustifyContent } from '@ui5/webcomponents-react/lib/FlexBoxJustifyContent';
55
import * as React from 'react';
6+
import sinon from 'sinon';
67

78
describe('FlexBox', () => {
89
test('JustifyContent: End', () => {
@@ -45,5 +46,17 @@ describe('FlexBox', () => {
4546
expect(wrapper.render()).toMatchSnapshot();
4647
});
4748

49+
test('pass through click handler', () => {
50+
const callback = sinon.spy();
51+
const wrapper = mount(
52+
// @ts-ignore
53+
<FlexBox onClick={callback}>
54+
<span>Test 1</span>
55+
</FlexBox>
56+
);
57+
wrapper.simulate('click');
58+
expect(callback.called).toBe(true);
59+
});
60+
4861
createPassThroughPropsTest(FlexBox);
4962
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ const Form: FC<FormPropTypes> = forwardRef((props: FormPropTypes, ref: Ref<HTMLD
7979
)}
8080
<Grid
8181
ref={ref}
82-
children={formGroups}
8382
defaultSpan={'XL6 L12 M12 S12'}
8483
className={className}
8584
slot={slot}
8685
style={style}
8786
tooltip={tooltip}
8887
{...passThroughProps}
89-
/>
88+
>
89+
{formGroups}
90+
</Grid>
9091
</CurrentViewportRangeContext.Provider>
9192
);
9293
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ const Notification: FC<NotificationProptypes> = forwardRef(
244244
<div
245245
style={notificationContainerStyles}
246246
className={`${classes.notificationContainer} ${className}`}
247-
onClick={handleNotificationClick}
248247
title={tooltip}
249248
ref={ref}
250249
{...passThroughProps}
250+
onClick={handleNotificationClick}
251251
>
252252
<div className={`${classes.priorityIndicator} ${indicatorClass}`} style={indicatorStyles} />
253253
<div style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ const SegmentedButtonItem: FC<SegmentedButtonItemPropTypes> = forwardRef(
7575
<li
7676
ref={ref}
7777
className={segmentedButtonItemClasses.valueOf()}
78-
onClick={handleOnClick}
7978
style={inlineStyles}
8079
title={tooltip}
8180
data-has-own-width={!!width}
8281
{...passThroughProps}
82+
onClick={handleOnClick}
8383
>
8484
{icon && <div className={iconClasses.valueOf()}>{icon}</div>}
8585
{children}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ const VariantManagement: FC<VariantManagementPropTypes> = forwardRef(
156156
<Popover
157157
ref={ref}
158158
open={open}
159-
onAfterOpen={handleAfterOpen}
160159
headerText={popupTitle}
161160
placementType={placement}
162161
openBy={variantManagementButton}
@@ -166,6 +165,7 @@ const VariantManagement: FC<VariantManagementPropTypes> = forwardRef(
166165
style={style}
167166
tooltip={tooltip}
168167
{...passThroughProps}
168+
onAfterOpen={handleAfterOpen}
169169
>
170170
<List onItemClick={handleVariantItemSelect} mode={ListMode.SingleSelect}>
171171
{variantItems.map((item) => (

packages/main/src/webComponents/Button/demo.stories.tsx

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,6 @@ import { Button } from '@ui5/webcomponents-react/lib/Button';
44
import { ButtonDesign } from '@ui5/webcomponents-react/lib/ButtonDesign';
55
import React from 'react';
66

7-
const customStyle1 = {
8-
color: 'red'
9-
};
10-
11-
const customStyle2 = {
12-
width: '15rem'
13-
};
14-
15-
class DemoButton extends React.Component {
16-
state = {
17-
showCS1: false,
18-
showCS2: false
19-
};
20-
21-
render() {
22-
const { showCS1, showCS2 } = this.state;
23-
24-
const innerStyles = {
25-
...(showCS1 ? customStyle1 : {}),
26-
...(showCS2 ? customStyle2 : {})
27-
};
28-
29-
return (
30-
<div>
31-
<div>
32-
<Button onClick={() => this.setState({ showCS1: !showCS1 })}>Toggle Custom Style 1</Button>
33-
<Button onClick={() => this.setState({ showCS2: !showCS2 })}>Toggle Custom Style 2</Button>
34-
</div>
35-
<Button
36-
design={select('design', ButtonDesign, ButtonDesign.Default)}
37-
disabled={boolean('disabled', false)}
38-
icon={'add'}
39-
iconEnd={boolean('iconEnd', false)}
40-
onClick={action('Button clicked')}
41-
innerStyles={innerStyles}
42-
>
43-
Some Content
44-
</Button>
45-
</div>
46-
);
47-
}
48-
}
49-
507
export default {
518
title: 'UI5 Web Components / Button',
529
component: Button
@@ -67,9 +24,3 @@ export const generatedDefaultStory = () => (
6724
generatedDefaultStory.story = {
6825
name: 'Generated default story'
6926
};
70-
71-
export const withCustomStyles = () => <DemoButton />;
72-
73-
withCustomStyles.story = {
74-
name: 'With custom Styles'
75-
};

0 commit comments

Comments
 (0)