/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/components/src/base-control/hooks.ts
34 строки
787 B
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { useInstanceId } from '@wordpress/compose'; import BaseControl from '.'; import type { BaseControlProps } from './types'; /** * Generate props for the `BaseControl` and the inner control itself. * * Namely, it takes care of generating a unique `id`, properly associating it with the `label` and `help` elements. * * @param props */ export function useBaseControlProps( props: Omit< BaseControlProps, 'children' > ) { const { help, id: preferredId, ...restProps } = props; const uniqueId = useInstanceId( BaseControl, 'wp-components-base-control', preferredId ); return { baseControlProps: { id: uniqueId, help, ...restProps, }, controlProps: { id: uniqueId, ...( !! help ? { 'aria-describedby': `${ uniqueId }__help` } : {} ), }, }; }