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

ToggleGroupControl: Add de-selectable variant #45123

Merged
merged 29 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f1c3899
Extract radio logic to subcomponent
mirka Oct 20, 2022
3dd5803
Fix wrong types
mirka Oct 19, 2022
fb1686a
Remove borderless prop
mirka Oct 20, 2022
eb2b7e4
Remove `multiple` prop
mirka Oct 20, 2022
201f56d
Add deselectability
mirka Oct 26, 2022
13a2850
Clean up
mirka Sep 14, 2022
b2cfd46
Rename buttonActive → buttonPressed
mirka Oct 19, 2022
9a991c2
Fix up button styles
mirka Oct 19, 2022
ab58915
Adjust focus styles
mirka Sep 14, 2022
206f943
Remove invalid style
mirka Sep 14, 2022
835f221
Update snapshots
mirka Oct 26, 2022
882a255
Add tests
mirka Sep 14, 2022
5fd20ff
Fix e2e test to use standard attribute
mirka Oct 19, 2022
bfe7d08
Fixup
mirka Oct 20, 2022
291ad4d
Rename for consistency
mirka Oct 19, 2022
3ed6cc5
Simplify
mirka Oct 19, 2022
8d5274b
Fixup icon misalignment
mirka Oct 19, 2022
be10945
Update snapshot
mirka Oct 26, 2022
958eab7
Update changelog
mirka Oct 19, 2022
bb9bb8d
Apply suggestions from code review
mirka Oct 21, 2022
c51d8a2
Pick types for styles
mirka Oct 21, 2022
1a7fa58
Remove unused `toggleGroupControlBackdropBoxShadow`
mirka Oct 21, 2022
fa5d95c
Don't let `as` prop on Radio to be overwritten
mirka Oct 26, 2022
013d1c0
Refactor ToggleGroupControlContextProps to clarify intent
mirka Oct 26, 2022
245b792
Add comment about otherContextProps
mirka Oct 26, 2022
5591154
ToggleGroupControlOptionBase: Refactor common props
mirka Oct 26, 2022
32e3505
Remove `__experimentalIsBorderless` from layout controls
mirka Oct 26, 2022
c3f187b
Merge branch 'trunk' into toggle-group-deselectable
mirka Oct 27, 2022
7996817
Fix changelog
mirka Oct 27, 2022
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
1 change: 0 additions & 1 deletion packages/block-editor/src/layouts/constrained.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export default {
) }
</p>
<ToggleGroupControl
__experimentalIsBorderless
label={ __( 'Justification' ) }
value={ justifyContent }
onChange={ onJustificationChange }
Expand Down
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
- `Navigator`: prevent partially hiding focus ring styles, by removing unnecessary overflow rules on `NavigatorScreen` ([#44973](https://github.com/WordPress/gutenberg/pull/44973)).
- `Navigator`: restore focus only once per location ([#44972](https://github.com/WordPress/gutenberg/pull/44972)).

### Enhancements

- `ToggleGroupControl`: Add `isDeselectable` prop to allow deselecting the selected option ([#45123](https://github.com/WordPress/gutenberg/pull/45123)).

mirka marked this conversation as resolved.
Show resolved Hide resolved
### Documentation

- `VisuallyHidden`: Add some notes on best practices around stacking contexts when using this component ([#44867](https://github.com/WordPress/gutenberg/pull/44867)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ WithIcons.args = {
};

/**
* A borderless style may be preferred in some contexts.
* When the `isDeselectable` prop is true, the option can be deselected by clicking on it again.
*/
export const Borderless: ComponentStory< typeof ToggleGroupControl > =
export const Deselectable: ComponentStory< typeof ToggleGroupControl > =
Template.bind( {} );
Borderless.args = {
Deselectable.args = {
...WithIcons.args,
__experimentalIsBorderless: true,
isDeselectable: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
.emotion-8 {
background: #fff;
border: 1px solid transparent;
border-radius: 2px;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
Expand All @@ -53,6 +52,7 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
transition: transform 100ms linear;
min-height: 36px;
border-color: #757575;
border-radius: 2px;
}

@media ( prefers-reduced-motion: reduce ) {
Expand All @@ -61,21 +61,20 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
}
}

.emotion-8:hover {
border-color: #757575;
}

.emotion-8:focus-within {
border-color: var( --wp-admin-theme-color-darker-10, #006ba1);
box-shadow: 0 0 0 0.5px var( --wp-admin-theme-color, #007cba);
outline: none;
z-index: 1;
}

.emotion-8:hover {
border-color: #757575;
}

.emotion-10 {
background: #1e1e1e;
border-radius: 2px;
box-shadow: transparent;
left: 0;
position: absolute;
top: 2px;
Expand Down Expand Up @@ -142,6 +141,11 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
user-select: none;
width: 100%;
z-index: 2;
color: #1e1e1e;
width: 30px;
padding-left: 0;
padding-right: 0;
color: #fff;
}

@media ( prefers-reduced-motion: reduce ) {
Expand All @@ -158,24 +162,75 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
background: #fff;
}

.emotion-14:active {
background: transparent;
}

.emotion-15 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
font-size: 13px;
line-height: 1;
}

.emotion-19 {
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
appearance: none;
background: transparent;
border: none;
border-radius: 2px;
color: #757575;
fill: currentColor;
cursor: pointer;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
font-family: inherit;
height: 100%;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
line-height: 100%;
outline: none;
padding: 0 12px;
position: relative;
text-align: center;
-webkit-transition: background 160ms linear,color 160ms linear,font-weight 60ms linear;
transition: background 160ms linear,color 160ms linear,font-weight 60ms linear;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
width: 100%;
z-index: 2;
color: #1e1e1e;
width: 30px;
padding-left: 0;
padding-right: 0;
}

.emotion-16 {
color: #fff;
@media ( prefers-reduced-motion: reduce ) {
.emotion-19 {
transition-duration: 0ms;
}
}

.emotion-16:active {
background: transparent;
.emotion-19::-moz-focus-inner {
border: 0;
}

.emotion-17 {
font-size: 13px;
line-height: 1;
.emotion-19:active {
background: #fff;
}

<div>
Expand All @@ -199,7 +254,7 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
class="components-toggle-group-control emotion-8 emotion-9"
data-wp-c16t="true"
data-wp-component="ToggleGroupControl"
id="toggle-group-control-1"
id="toggle-group-control-as-radio-group-1"
role="radiogroup"
>
<div
Expand All @@ -213,21 +268,20 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
/>
<div
class="emotion-12 emotion-13"
data-active="true"
>
<button
aria-checked="true"
aria-label="Uppercase"
class="emotion-14 emotion-15 components-toggle-group-control-option-base emotion-16"
class="emotion-14 components-toggle-group-control-option-base"
data-value="uppercase"
data-wp-c16t="true"
data-wp-component="ToggleGroupControlOptionBase"
id="toggle-group-control-1-2"
id="toggle-group-control-as-radio-group-1-2"
role="radio"
tabindex="0"
>
<div
class="emotion-17 emotion-18"
class="emotion-15 emotion-16"
>
<svg
aria-hidden="true"
Expand All @@ -246,21 +300,20 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
</div>
<div
class="emotion-12 emotion-13"
data-active="false"
>
<button
aria-checked="false"
aria-label="Lowercase"
class="emotion-14 emotion-15 components-toggle-group-control-option-base"
class="emotion-19 components-toggle-group-control-option-base"
data-value="lowercase"
data-wp-c16t="true"
data-wp-component="ToggleGroupControlOptionBase"
id="toggle-group-control-1-3"
id="toggle-group-control-as-radio-group-1-3"
role="radio"
tabindex="-1"
>
<div
class="emotion-17 emotion-18"
class="emotion-15 emotion-16"
>
<svg
aria-hidden="true"
Expand Down Expand Up @@ -324,7 +377,6 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
.emotion-8 {
background: #fff;
border: 1px solid transparent;
border-radius: 2px;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
Expand All @@ -336,6 +388,7 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
transition: transform 100ms linear;
min-height: 36px;
border-color: #757575;
border-radius: 2px;
}

@media ( prefers-reduced-motion: reduce ) {
Expand All @@ -344,17 +397,17 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
}
}

.emotion-8:hover {
border-color: #757575;
}

.emotion-8:focus-within {
border-color: var( --wp-admin-theme-color-darker-10, #006ba1);
box-shadow: 0 0 0 0.5px var( --wp-admin-theme-color, #007cba);
outline: none;
z-index: 1;
}

.emotion-8:hover {
border-color: #757575;
}

.emotion-10 {
display: -webkit-inline-box;
display: -webkit-inline-flex;
Expand Down Expand Up @@ -423,6 +476,10 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
}

.emotion-13 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
font-size: 13px;
line-height: 1;
}
Expand All @@ -448,7 +505,7 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
class="components-toggle-group-control emotion-8 emotion-9"
data-wp-c16t="true"
data-wp-component="ToggleGroupControl"
id="toggle-group-control-0"
id="toggle-group-control-as-radio-group-0"
role="radiogroup"
>
<div
Expand All @@ -457,7 +514,6 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
/>
<div
class="emotion-10 emotion-11"
data-active="false"
>
<button
aria-checked="false"
Expand All @@ -466,7 +522,7 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
data-value="rigas"
data-wp-c16t="true"
data-wp-component="ToggleGroupControlOptionBase"
id="toggle-group-control-0-0"
id="toggle-group-control-as-radio-group-0-0"
role="radio"
tabindex="0"
>
Expand All @@ -479,7 +535,6 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
</div>
<div
class="emotion-10 emotion-11"
data-active="false"
>
<button
aria-checked="false"
Expand All @@ -488,7 +543,7 @@ exports[`ToggleGroupControl should render correctly with text options 1`] = `
data-value="jack"
data-wp-c16t="true"
data-wp-component="ToggleGroupControlOptionBase"
id="toggle-group-control-0-1"
id="toggle-group-control-as-radio-group-0-1"
role="radio"
tabindex="-1"
>
Expand Down
Loading