Skip to content

Commit

Permalink
fix(Button): onClick can now be set using context provider (#3781)
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrekim authored Aug 19, 2024
1 parent da4ed49 commit 0d2f525
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/dnb-eufemia/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export default class Button extends React.PureComponent {
}
}

onClickHandler = (event) => {
const afterContent = dispatchCustomElementEvent(this, 'on_click', {
getOnClickHandler = (src) => (event) => {
const afterContent = dispatchCustomElementEvent(src, 'on_click', {
event,
})
if (afterContent && React.isValidElement(afterContent)) {
Expand Down Expand Up @@ -222,8 +222,8 @@ export default class Button extends React.PureComponent {
...attributes,
}

if (this.props.on_click || this.props.onClick) {
params.onClick = this.onClickHandler
if (props.on_click || props.onClick) {
params.onClick = this.getOnClickHandler(props)
}

if (Element !== Anchor && !params.type) {
Expand Down Expand Up @@ -386,6 +386,7 @@ Button.defaultProps = {
element: null,

on_click: null,
onClick: null,
}

function Content({
Expand Down

0 comments on commit 0d2f525

Please sign in to comment.