Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API: Allow "default" suffix values #65815

Merged
merged 11 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ class="foo bar baz"
data-testid="can toggle class when class attribute is missing"
></div>

<div data-wp-context='{ "falseValue": false }'>
<div data-wp-context='{ "value": false }'>
<div
class="foo"
data-wp-class--foo="context.falseValue"
data-wp-class--foo="context.value"
data-testid="can use context values"
></div>
<button
data-wp-on--click="actions.toggleContextFalseValue"
data-wp-on--click="actions.toggleContextValue"
data-testid="toggle context false value"
>
Toggle context falseValue
Toggle context value
</button>
</div>

Expand All @@ -83,4 +83,16 @@ class="foo"
data-testid="can use classes with several dashes"
></div>

<div data-wp-context='{ "value": false }'>
<div
data-wp-class--default="context.value"
data-testid="class name default"
></div>
<button
data-wp-on--click="actions.toggleContextValue"
data-testid="toggle class name default"
>
Toggle context val
</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const { state } = store( 'directive-class', {
toggleFalseValue: () => {
state.falseValue = ! state.falseValue;
},
toggleContextFalseValue: () => {
toggleContextValue: () => {
const context = getContext();
context.falseValue = ! context.falseValue;
context.value = ! context.value;
},
},
} );
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { directive } = privateApis(
directive(
'show-mock',
( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
const entry = showMock.find( ( { suffix } ) => suffix === null );
if ( ! evaluate( entry ) ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { directive } = privateApis(
directive(
'show-mock',
( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
const entry = showMock.find( ( { suffix } ) => suffix === null );
if ( ! evaluate( entry ) ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { directive } = privateApis(
directive(
'show-mock',
( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
const entry = showMock.find( ( { suffix } ) => suffix === null );
if ( ! evaluate( entry ) ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ directive(
element,
evaluate,
} ) => {
const entry = showChildren.find(
( { suffix } ) => suffix === 'default'
);
const entry = showChildren.find( ( { suffix } ) => suffix === null );
return evaluate( entry )
? element
: cloneElement( element, { children: null } );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { directive } = privateApis(
directive(
'show-mock',
( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
const entry = showMock.find( ( { suffix } ) => suffix === null );
if ( ! evaluate( entry ) ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { directive, h } = privateApis(
directive(
'show-mock',
( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
const entry = showMock.find( ( { suffix } ) => suffix === null );

if ( ! evaluate( entry ) ) {
element.props.children = h(
Expand Down
1 change: 1 addition & 0 deletions packages/interactivity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bug Fixes

- Fix an issue where "default" could not be used as a directive suffix ([#65815](https://github.com/WordPress/gutenberg/pull/65815)).
- Correctly handle lazily added, deeply nested properties with `deepMerge()` ([#65465](https://github.com/WordPress/gutenberg/pull/65465)).

## 6.9.0 (2024-10-03)
Expand Down
Loading
Loading