Skip to content

Commit

Permalink
fix(paths): break long paths with <wbr> (#7516)
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
MingweiSamuel committed Sep 30, 2021
1 parent 9952849 commit f88334a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/core/components/deep-link.jsx
Expand Up @@ -14,7 +14,7 @@ DeepLink.propTypes = {
enabled: PropTypes.bool,
isShown: PropTypes.bool,
path: PropTypes.string,
text: PropTypes.string
text: PropTypes.node
}

export default DeepLink
20 changes: 11 additions & 9 deletions src/core/components/operation-summary-path.jsx
Expand Up @@ -12,12 +12,6 @@ export default class OperationSummaryPath extends PureComponent{
getComponent: PropTypes.func.isRequired,
}

onCopyCapture = (e) => {
// strips injected zero-width spaces (`\u200b`) from copied content
e.clipboardData.setData("text/plain", this.props.operationProps.get("path"))
e.preventDefault()
}

render(){
let {
getComponent,
Expand All @@ -34,17 +28,25 @@ export default class OperationSummaryPath extends PureComponent{
isDeepLinkingEnabled,
} = operationProps.toJS()

/**
* Add <wbr> word-break elements between each segment, before the slash
* to allow browsers an opportunity to break long paths into sensible segments.
*/
const pathParts = path.split(/(?=\/)/g)
for (let i = 1; i < pathParts.length; i += 2) {
pathParts.splice(i, 0, <wbr key={i} />)
}

const DeepLink = getComponent( "DeepLink" )

return(
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" }
onCopyCapture={this.onCopyCapture}
<span className={ deprecated ? "opblock-summary-path__deprecated" : "opblock-summary-path" }
data-path={path}>
<DeepLink
enabled={isDeepLinkingEnabled}
isShown={isShown}
path={createDeepLinkPath(`${tag}/${operationId}`)}
text={path.replace(/\//g, "\u200b/")} />
text={pathParts} />
</span>

)
Expand Down

0 comments on commit f88334a

Please sign in to comment.