Skip to content

Commit c2d8e69

Browse files
committed
fix: focus the fix in how typography handle dynamic content
1 parent 41a9190 commit c2d8e69

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

  • src
    • block-components/typography
    • components/dynamic-content-control

‎src/block-components/typography/edit.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ export const Controls = props => {
116116
value={ unescape( text ) }
117117
onChange={ onChangeContent }
118118
/**
119-
* Pass the unescaped Dynamic Content `onChange` function.
119+
* Dynamic Content generates this markup itself. Preserve it because
120+
* HTML validation normalizes string ampersands in its attribute.
120121
*
121122
* @param {string} text Text with dynamic content.
122123
*/
123-
changeDynamicContent={ onChangeContent }
124+
changeDynamicContent={ text => updateAttribute( 'text', text ) }
124125
isDynamic={ true }
125126
/>
126127
) }

‎src/components/dynamic-content-control/index.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { QueryLoopContext } from '~stackable/higher-order/with-query-loop-contex
1515
*/
1616
import { __ } from '@wordpress/i18n'
1717
import { useBlockEditContext } from '@wordpress/block-editor'
18-
import { escapeAttribute } from '@wordpress/escape-html'
1918
import {
2019
Button,
2120
TextControl,
@@ -123,10 +122,8 @@ export const useDynamicContentControlProps = props => {
123122

124123
const onChange = ( newValue, editorQueryString, frontendQueryString ) => {
125124
// If `isFormatType` is true, the onChange function will generate a `stackable/dynamic-content` format type.
126-
// Custom date formats add query parameters with "&"" character. Escape it so
127-
// HTML validation in Typography preserves this as markup, not text.
128125
const willChangeValue = props.isFormatType
129-
? `<span data-stk-dynamic="${ escapeAttribute( frontendQueryString ) }" contenteditable="false" class="stk-dynamic-content">${ newValue }</span>`
126+
? `<span data-stk-dynamic="${ frontendQueryString }" contenteditable="false" class="stk-dynamic-content">${ newValue }</span>`
130127
: `!#stk_dynamic/${ frontendQueryString }!#`
131128

132129
props.onChange( willChangeValue )

0 commit comments

Comments
 (0)