Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit dfe0b63

Browse files
committed
n_clicks_previous doesn't work
n_clicks_previous won’t work unless dash-renderer is handling - it’ll always just be n_clicks - 1. Instead, we could attach a timestamp to the event and use that for comparison. This is a stopgap until we serve this property for all components in the framework itself.
1 parent 6e78386 commit dfe0b63

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

scripts/generate-components.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,11 @@ function generatePropTypes(element, attributes) {
6060
'n_clicks': PropTypes.integer,
6161
6262
/**
63-
* An integer that represents the number of times
64-
* that this element was clicked on. If this is the same as
65-
* \`n_clicks\`, then the button wasn't clicked on.
66-
* If it is less than \`n_clicks\`, then the button
67-
* was clicked on. This is useful in callbacks that have
68-
* multiple buttons and you need to know _which_ button
69-
* was clicked on.
63+
* An integer that represents the time (in ms since 1970)
64+
* at which n_clicks changed. This can be used to tell
65+
* which button was changed most recently.
7066
*/
71-
'n_clicks_previous': PropTypes.integer,
67+
'n_clicks_timestamp': PropTypes.integer,
7268
7369
/**
7470
* A unique identifier for the component, used to improve
@@ -128,13 +124,10 @@ const ${Component} = (props) => {
128124
<${element}
129125
onClick={() => {
130126
if (props.setProps) {
131-
const newProps = {
132-
n_clicks: props.n_clicks + 1
133-
}
134-
if (newProps.n_clicks > 1) {
135-
newProps.n_clicks_previous = props.n_clicks_previous + 1;
136-
}
137-
props.setProps(newProps);
127+
props.setProps({
128+
n_clicks: props.n_clicks + 1,
129+
n_clicks_timestamp: Date.now()
130+
})
138131
}
139132
if (props.fireEvent) props.fireEvent({event: 'click'});
140133
}}
@@ -147,7 +140,7 @@ const ${Component} = (props) => {
147140
148141
${Component}.defaultProps = {
149142
n_clicks: 0,
150-
n_clicks_previous: 0
143+
n_clicks_timestamp: -1
151144
};
152145
153146
${Component}.propTypes = {${propTypes}

0 commit comments

Comments
 (0)