Skip to content

Commit 9c0c9d7

Browse files
authored
Merge branch 'dev' into fix/devtool-overflow
2 parents 5f1cbd5 + 9bbbc0c commit 9c0c9d7

3 files changed

Lines changed: 66 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
55
## [UNRELEASED]
66

77
## Added
8-
- [#3534]((https://github.com/plotly/dash/pull/3534) Adds `playsInline` prop to `html.Video`. Based on [#2338](https://github.com/plotly/dash/pull/2338)
8+
9+
- [#3568]((https://github.com/plotly/dash/pull/3568) Added `children` and `copied_children` props to `dcc.Clipboard` to customize the button contents before and after copying.
10+
- [#3534]((https://github.com/plotly/dash/pull/3534) Adds `playsInline` prop to `html.Video`. Based on [#2338]((https://github.com/plotly/dash/pull/2338)
911
- [#3541](https://github.com/plotly/dash/pull/3541) Add `attributes` dictionary to be be formatted on script/link (_js_dist/_css_dist) tags of the index, allows for `type="module"` or `type="importmap"`. [#3538](https://github.com/plotly/dash/issues/3538)
1012
- [#3542](https://github.com/plotly/dash/pull/3542) Add hidden=True to dash pages callback.
1113
- [#3564](https://github.com/plotly/dash/pull/3564) Add new parameter `hide_all_callbacks` to `run()`. Closes [#3493](https://github.com/plotly/dash/issues/3493)

components/dash-core-components/src/components/Clipboard.react.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,14 @@ export default class Clipboard extends React.Component {
128128
}
129129

130130
render() {
131-
const {id, title, className, style} = this.props;
132-
const copyIcon = <FontAwesomeIcon icon={faCopy} />;
133-
const copiedIcon = <FontAwesomeIcon icon={faCheckCircle} />;
134-
const btnIcon = this.state.copied ? copiedIcon : copyIcon;
131+
const {id, title, className, style, children, copied_children} =
132+
this.props;
133+
134+
const isCopied = this.state.copied;
135+
136+
const button_children = isCopied
137+
? copied_children ?? <FontAwesomeIcon icon={faCheckCircle} />
138+
: children ?? <FontAwesomeIcon icon={faCopy} />;
135139

136140
return clipboardAPI ? (
137141
<LoadingElement
@@ -141,7 +145,7 @@ export default class Clipboard extends React.Component {
141145
className={className}
142146
onClick={this.onClickHandler}
143147
>
144-
<i> {btnIcon}</i>
148+
{button_children}
145149
</LoadingElement>
146150
) : null;
147151
}
@@ -160,6 +164,16 @@ Clipboard.propTypes = {
160164
*/
161165
id: PropTypes.string,
162166

167+
/**
168+
* Children rendered inside the Clipboard button before copying. By default, a copy icon.
169+
*/
170+
children: PropTypes.node,
171+
172+
/**
173+
* Children rendered inside the Clipboard button after the value has been copied. By default, a check icon.
174+
*/
175+
copied_children: PropTypes.node,
176+
163177
/**
164178
* The id of target component containing text to copy to the clipboard.
165179
* The inner text of the `children` prop will be copied to the clipboard. If none, then the text from the
@@ -173,7 +187,7 @@ Clipboard.propTypes = {
173187
content: PropTypes.string,
174188

175189
/**
176-
* The number of times copy button was clicked
190+
* The number of times Clipboard button was clicked
177191
*/
178192
n_clicks: PropTypes.number,
179193

components/dash-core-components/tests/integration/clipboard/test_clipboard.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,46 @@ def selected(icon_clicks, button_clicks):
9090
== copy_text,
9191
timeout=3,
9292
)
93+
94+
95+
def test_clp004_clipboard_children_and_copied_children(dash_dcc_headed):
96+
content = "https://dash.plotly.com/"
97+
children_text = "Copy URL"
98+
copied_children_text = "Copied!"
99+
100+
app = Dash(__name__, prevent_initial_callbacks=True)
101+
app.layout = html.Div(
102+
[
103+
dcc.Clipboard(
104+
id="clipboard",
105+
children=children_text,
106+
copied_children=copied_children_text,
107+
content=content,
108+
),
109+
dcc.Textarea(id="textarea"),
110+
]
111+
)
112+
113+
dash_dcc_headed.start_server(app)
114+
115+
clipboard = dash_dcc_headed.find_element("#clipboard")
116+
117+
assert clipboard.text == children_text
118+
119+
clipboard.click()
120+
wait.until(
121+
lambda: dash_dcc_headed.find_element("#clipboard").text == copied_children_text,
122+
timeout=3,
123+
)
124+
textarea = dash_dcc_headed.find_element("#textarea")
125+
textarea.click()
126+
127+
ActionChains(dash_dcc_headed.driver).key_down(Keys.CONTROL).send_keys("v").key_up(
128+
Keys.CONTROL
129+
).perform()
130+
131+
wait.until(
132+
lambda: dash_dcc_headed.find_element("#textarea").get_attribute("value")
133+
== content,
134+
timeout=3,
135+
)

0 commit comments

Comments
 (0)