diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 967084192afd83..6649fb699fbbbd 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -17,6 +17,7 @@ - `Tabs`: Replace `rem` with `px` in tablist overflow fade ([#72669](https://github.com/WordPress/gutenberg/pull/72669)). - `Modal`: Replace `rem` in heading text with a standard `px` value ([#72669](https://github.com/WordPress/gutenberg/pull/72669)). - Validated form controls: Replace `rem` with `px` in error message ([#72669](https://github.com/WordPress/gutenberg/pull/72669)). +- `FocalPointPicker`: Fix label markup ([#70835](https://github.com/WordPress/gutenberg/pull/70835)). ## 30.6.0 (2025-10-17) diff --git a/packages/components/src/focal-point-picker/index.tsx b/packages/components/src/focal-point-picker/index.tsx index cad14aff5b693f..3485893860f322 100644 --- a/packages/components/src/focal-point-picker/index.tsx +++ b/packages/components/src/focal-point-picker/index.tsx @@ -2,6 +2,7 @@ * External dependencies */ import clsx from 'clsx'; +import type { KeyboardEventHandler } from 'react'; /** * WordPress dependencies @@ -10,19 +11,19 @@ import { __ } from '@wordpress/i18n'; import { useEffect, useRef, useState } from '@wordpress/element'; import { __experimentalUseDragging as useDragging, - useInstanceId, useIsomorphicLayoutEffect, } from '@wordpress/compose'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies */ -import BaseControl from '../base-control'; import Controls from './controls'; import FocalPoint from './focal-point'; import Grid from './grid'; import Media from './media'; import { + Container, MediaWrapper, MediaContainer, } from './styles/focal-point-picker-style'; @@ -33,7 +34,11 @@ import type { FocalPoint as FocalPointType, FocalPointPickerProps, } from './types'; -import type { KeyboardEventHandler } from 'react'; +import { + StyledLabel, + StyledHelp, +} from '../base-control/styles/base-control-styles'; +import { VisuallyHidden } from '../visually-hidden'; const GRID_OVERLAY_TIMEOUT = 600; @@ -88,6 +93,7 @@ export function FocalPointPicker( { autoPlay = true, className, help, + hideLabelFromVision, label, onChange, onDrag, @@ -104,6 +110,14 @@ export function FocalPointPicker( { const [ point, setPoint ] = useState( valueProp ); const [ showGridOverlay, setShowGridOverlay ] = useState( false ); + if ( ! __nextHasNoMarginBottom ) { + deprecated( 'Bottom margin styles for wp.components.FocalPointPicker', { + since: '6.7', + version: '7.0', + hint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version.', + } ); + } + const { startDrag, endDrag, isDragging } = useDragging( { onDragStart: ( event ) => { dragAreaRef.current?.focus(); @@ -233,9 +247,7 @@ export function FocalPointPicker( { }; const classes = clsx( 'components-focal-point-picker-control', className ); - - const instanceId = useInstanceId( FocalPointPicker ); - const id = `inspector-focal-point-picker-control-${ instanceId }`; + const Label = hideLabelFromVision ? VisuallyHidden : StyledLabel; useUpdateEffect( () => { setShowGridOverlay( true ); @@ -247,15 +259,8 @@ export function FocalPointPicker( { }, [ x, y ] ); return ( - + + { !! label && } - + { !! help && ( + + { help } + + ) } + ); } diff --git a/packages/components/src/focal-point-picker/styles/focal-point-picker-style.ts b/packages/components/src/focal-point-picker/styles/focal-point-picker-style.ts index 01565313e06ebb..3d562d9108422f 100644 --- a/packages/components/src/focal-point-picker/styles/focal-point-picker-style.ts +++ b/packages/components/src/focal-point-picker/styles/focal-point-picker-style.ts @@ -9,10 +9,20 @@ import styled from '@emotion/styled'; */ import { Flex } from '../../flex'; import UnitControl from '../../unit-control'; -import { COLORS, CONFIG } from '../../utils'; +import { View } from '../../view'; +import { COLORS, CONFIG, boxSizingReset, font } from '../../utils'; import type { FocalPointPickerControlsProps } from '../types'; import { INITIAL_BOUNDS } from '../utils'; +export const Container = styled( View )` + border: 0; + padding: 0; + margin: 0; + font-family: ${ font( 'default.fontFamily' ) }; + font-size: ${ font( 'default.fontSize' ) }; + ${ boxSizingReset } +`; + export const MediaWrapper = styled.div` background-color: transparent; display: flex;