Skip to content

Commit

Permalink
fix(SegmentedButton): call onClick prop on SegmentedButtonItem if set (
Browse files Browse the repository at this point in the history
  • Loading branch information
vbersch authored Nov 7, 2019
1 parent 82d1069 commit bc9bef3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/main/src/components/SegmentedButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ const SegmentedButton: FC<SegmentedButtonPropTypes> = forwardRef(
}

const handleSegmentedButtonItemSelected = useCallback(
(e) => {
(originalOnclick) => (e) => {
const newSelectedKey = e.getParameter('selectedKey');
if (newSelectedKey !== internalSelectedKey) {
setSelectedKey(newSelectedKey);
if (typeof onItemSelected === 'function') {
onItemSelected(Event.of(null, e.getOriginalEvent(), e.getParameters()));
}
}
if (typeof originalOnclick === 'function') {
originalOnclick(e);
}
},
[internalSelectedKey, setSelectedKey, onItemSelected]
);
Expand Down Expand Up @@ -125,7 +128,7 @@ const SegmentedButton: FC<SegmentedButtonPropTypes> = forwardRef(
key: item.props.id,
selected: internalSelectedKey === item.props.id,
disabled: disabled === true ? disabled : item.props.disabled,
onClick: handleSegmentedButtonItemSelected
onClick: handleSegmentedButtonItemSelected(item.props.onClick)
})
)}
</ul>
Expand Down

0 comments on commit bc9bef3

Please sign in to comment.