Skip to content
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- Remove `ValidatedNumberControl` from the private APIs; it now lives internally in `@wordpress/dataviews`, its only consumer ([#81433](https://github.com/WordPress/gutenberg/pull/81433)).
- Remove `ValidatedRadioControl` from the private APIs; it now lives internally in `@wordpress/dataviews`, its only consumer ([#81434](https://github.com/WordPress/gutenberg/pull/81434)).
- Remove `ValidatedFormTokenField` from the private APIs; it now lives internally in `@wordpress/dataviews`, its only consumer ([#81451](https://github.com/WordPress/gutenberg/pull/81451)).
- Remove `ValidatedToggleGroupControl` from the private APIs; it now lives internally in `@wordpress/dataviews`, its only consumer ([#81450](https://github.com/WordPress/gutenberg/pull/81450)).
- Remove `ValidatedSelectControl` from the private APIs; it now lives internally in `@wordpress/dataviews`, its only consumer ([#81391](https://github.com/WordPress/gutenberg/pull/81391)).
- Move `withIgnoreIMEEvents` to `@wordpress/keycodes`, where it is now a public API, and remove it from this package's private APIs ([#81343](https://github.com/WordPress/gutenberg/pull/81343)).
- Extract the private `kebabCase` utility to the new `@wordpress/kebab-case` package and remove it from the private APIs; all consumers now use the package directly ([#81294](https://github.com/WordPress/gutenberg/pull/81294)).
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/private-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
ValidatedContentEditableControl,
ValidatedTextareaControl,
ValidatedToggleControl,
ValidatedToggleGroupControl,
} from './validated-form-controls';
import ContentEditableControl from './content-editable-control';

Expand All @@ -27,5 +26,4 @@ lock( privateApis, {
ValidatedContentEditableControl,
ValidatedTextareaControl,
ValidatedToggleControl,
ValidatedToggleGroupControl,
} );
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export * from './range-control';
export * from './content-editable-control';
export * from './textarea-control';
export * from './toggle-control';
export * from './toggle-group-control';
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ We don't foresee these being needed much, but it is technically possible by the

### Delegate elements

The implementations for `ToggleGroupControl` and `CustomSelectControl` use a "delegate" element for validation, due to upstream limitations that prevent us from using the actual underlying elements for constraint validation. A delegate element in this context is a visually hidden form element that we "delegate" the Constraint Validation API concerns to.
The implementation for `CustomSelectControl` uses a "delegate" element for validation, due to upstream limitations that prevent us from using the actual underlying elements for constraint validation. A delegate element in this context is a visually hidden form element that we "delegate" the Constraint Validation API concerns to.

This is not ideal, but lets us maintain a consistent mechanism to scroll to the invalid field when attempting to submit, and block the form from submitting. It is hopefully fine as a stopgap, given the low amount of actual validation that will need happen on these two specific components.
This is not ideal, but lets us maintain a consistent mechanism to scroll to the invalid field when attempting to submit, and block the form from submitting. It is hopefully fine as a stopgap, given the low amount of actual validation that will need happen on this specific component.

### Controlled mode only

Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions packages/components/src/validated-form-controls/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
border-color: $alert-red;
}

// For ToggleGroupControl
&:has(input[type="radio"]:invalid[data-validity-visible]) {
--wp-components-color-accent: #{$alert-red};
}

// For ContentEditableControl
&:has(input:invalid[data-validity-visible])
.components-validated-control__content-editable [role="textbox"] {
Expand Down
1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- DataForm: Internalize `ValidatedNumberControl` instead of unlocking it from the `@wordpress/components` private APIs. [#81433](https://github.com/WordPress/gutenberg/pull/81433)
- DataForm: Internalize `ValidatedRadioControl` instead of unlocking it from the `@wordpress/components` private APIs. [#81434](https://github.com/WordPress/gutenberg/pull/81434)
- DataForm: Internalize `ValidatedFormTokenField` instead of unlocking it from the `@wordpress/components` private APIs. [#81451](https://github.com/WordPress/gutenberg/pull/81451)
- DataForm: Internalize `ValidatedToggleGroupControl` instead of unlocking it from the `@wordpress/components` private APIs. [#81450](https://github.com/WordPress/gutenberg/pull/81450)

### New Features

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {
privateApis,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
Spinner,
} from '@wordpress/components';
import { useCallback } from '@wordpress/element';
import type { DataFormControlProps } from '../../types';
import { unlock } from '../../lock-unlock';
import { ValidatedToggleGroupControl } from '../validated-form-controls';
import getCustomValidity from './utils/get-custom-validity';
import useElements from '../../hooks/use-elements';

const { ValidatedToggleGroupControl } = unlock( privateApis );

export default function ToggleGroup< Item >( {
data,
field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export { ValidatedFormTokenField } from './form-token-field';
export { ValidatedNumberControl } from './number-control';
export { ValidatedRadioControl } from './radio-control';
export { ValidatedSelectControl } from './select-control';
export { ValidatedToggleGroupControl } from './toggle-group-control';
export type { ValidatedControlProps } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
--wp-admin-theme-color: #{$alert-red};
border-color: $alert-red;
}

// For ToggleGroupControl

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

&:has(input[type="radio"]:invalid[data-validity-visible]) {
--wp-components-color-accent: #{$alert-red};
}
}

.dataviews-validated-control__error-delegate {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen } from '@testing-library/react';
import { ValidatedToggleGroupControl } from '../components';
import { ToggleGroupControlOption } from '../../toggle-group-control';
import { __experimentalToggleGroupControlOption as ToggleGroupControlOption } from '@wordpress/components';
import { ValidatedToggleGroupControl } from '../toggle-group-control';

// The `help` prop is rendered visually by BaseControl but is not
// programmatically associated with the toggle group via aria-describedby.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import { forwardRef, useId, useRef } from '@wordpress/element';
import { ControlWithError } from '../control-with-error';
import { __experimentalToggleGroupControl as ToggleGroupControl } from '@wordpress/components';
import { ControlWithError } from './control-with-error';
import type { ValidatedControlProps } from './types';
import { ToggleGroupControl } from '../../toggle-group-control';

type ToggleGroupControlProps = React.ComponentProps<
typeof ToggleGroupControl
>;

type ValidatedToggleGroupControlProps = ToggleGroupControlProps &
ValidatedControlProps;

const UnforwardedValidatedToggleGroupControl = (
{
required,
customValidity,
markWhenOptional,
...restProps
}: React.ComponentProps< typeof ToggleGroupControl > &
ValidatedControlProps,
}: ValidatedToggleGroupControlProps,
forwardedRef: React.ForwardedRef< HTMLInputElement >
) => {
const validityTargetRef = useRef< HTMLInputElement >( null );

const nameAttr = useId();

return (
<div className="components-validated-control__wrapper-with-error-delegate">
<div className="dataviews-validated-control__wrapper-with-error-delegate">
<ControlWithError
required={ required }
markWhenOptional={ markWhenOptional }
Expand All @@ -28,7 +34,7 @@ const UnforwardedValidatedToggleGroupControl = (
<ToggleGroupControl ref={ forwardedRef } { ...restProps } />
</ControlWithError>
<input
className="components-validated-control__error-delegate"
className="dataviews-validated-control__error-delegate"
type="radio"
ref={ validityTargetRef }
required={ required }
Expand All @@ -49,7 +55,8 @@ const UnforwardedValidatedToggleGroupControl = (
);
};

export const ValidatedToggleGroupControl = forwardRef(
UnforwardedValidatedToggleGroupControl
);
export const ValidatedToggleGroupControl: React.ForwardRefExoticComponent<
React.PropsWithoutRef< ValidatedToggleGroupControlProps > &
React.RefAttributes< HTMLInputElement >
> = forwardRef( UnforwardedValidatedToggleGroupControl );
ValidatedToggleGroupControl.displayName = 'ValidatedToggleGroupControl';
Loading