Skip to content

Commit f88334a

Browse files
fix(paths): break long paths with <wbr> (#7516)
- use <wbr> instead of ZERO-WIDTH SPACE (U+200B) to break segments - remove no-longer-needed onCopyCapture listener which previously stripped ZWSPs - update's deep-link.jsx's `text` prop type to accept `PropType.node` to allow the above. Closes #7513 Co-authored-by: Vladimir Gorej <vladimir.gorej@gmail.com>
1 parent 9952849 commit f88334a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/core/components/deep-link.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DeepLink.propTypes = {
1414
enabled: PropTypes.bool,
1515
isShown: PropTypes.bool,
1616
path: PropTypes.string,
17-
text: PropTypes.string
17+
text: PropTypes.node
1818
}
1919

2020
export default DeepLink

src/core/components/operation-summary-path.jsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ export default class OperationSummaryPath extends PureComponent{
1212
getComponent: PropTypes.func.isRequired,
1313
}
1414

15-
onCopyCapture = (e) => {
16-
// strips injected zero-width spaces (`\u200b`) from copied content
17-
e.clipboardData.setData("text/plain", this.props.operationProps.get("path"))
18-
e.preventDefault()
19-
}
20-
2115
render(){
2216
let {
2317
getComponent,
@@ -34,17 +28,25 @@ export default class OperationSummaryPath extends PureComponent{
3428
isDeepLinkingEnabled,
3529
} = operationProps.toJS()
3630

31+
/**
32+
* Add <wbr> word-break elements between each segment, before the slash
33+
* to allow browsers an opportunity to break long paths into sensible segments.
34+
*/
35+
const pathParts = path.split(/(?=\/)/g)
36+
for (let i = 1; i < pathParts.length; i += 2) {
37+
pathParts.splice(i, 0, <wbr key={i} />)
38+
}
39+
3740
const DeepLink = getComponent( "DeepLink" )
3841

3942
return(
40-
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" }
41-
onCopyCapture={this.onCopyCapture}
43+
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" }
4244
data-path={path}>
4345
<DeepLink
4446
enabled={isDeepLinkingEnabled}
4547
isShown={isShown}
4648
path={createDeepLinkPath(`${tag}/${operationId}`)}
47-
text={path.replace(/\//g, "\u200b/")} />
49+
text={pathParts} />
4850
</span>
4951

5052
)

0 commit comments

Comments
 (0)