Skip to content

Commit 3455c42

Browse files
committed
[material-ui][Tooltip] Support event handlers with extra parameters
1 parent 9b620c4 commit 3455c42

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

packages/mui-material/src/Tooltip/Tooltip.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ export function testReset() {
223223
}
224224

225225
function composeEventHandler(handler, eventHandler) {
226-
return (event) => {
226+
return (event, ...params) => {
227227
if (eventHandler) {
228-
eventHandler(event);
228+
eventHandler(event, ...params);
229229
}
230-
handler(event);
230+
handler(event, ...params);
231231
};
232232
}
233233

packages/mui-material/src/Tooltip/Tooltip.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,45 @@ describe('<Tooltip />', () => {
962962
expect(handleFocus.callCount).to.equal(1);
963963
expect(handleFocus.returned(input)).to.equal(true);
964964
});
965+
966+
// https://github.com/mui/mui-x/issues/12248
967+
it('should support event handlers with extra parameters', () => {
968+
const handleFocus = spy((event, extra) => extra);
969+
const handleBlur = spy((event, ...params) => params);
970+
971+
const TextField = React.forwardRef(function TextField(props, ref) {
972+
const { onFocus, onBlur, ...other } = props;
973+
return (
974+
<div ref={ref} {...other}>
975+
<input
976+
type="text"
977+
onFocus={(event) => onFocus(event, 'focus')}
978+
onBlur={(event) => onBlur(event, 'blur', 1)}
979+
/>
980+
</div>
981+
);
982+
});
983+
render(
984+
<Tooltip open title="test">
985+
<TextField onFocus={handleFocus} onBlur={handleBlur} variant="standard" />
986+
</Tooltip>,
987+
);
988+
const input = screen.getByRole('textbox');
989+
990+
act(() => {
991+
input.focus();
992+
});
993+
994+
expect(handleFocus.callCount).to.equal(1);
995+
expect(handleFocus.returnValues[0]).to.equal('focus');
996+
997+
act(() => {
998+
input.blur();
999+
});
1000+
1001+
expect(handleBlur.callCount).to.equal(1);
1002+
expect(handleBlur.returnValues[0]).to.deep.equal(['blur', 1]);
1003+
});
9651004
});
9661005

9671006
describe('warnings', () => {

0 commit comments

Comments
 (0)