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

Adding support for defined IDs in TextControl component #52028

Merged
Changes from 1 commit
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
Prev Previous commit
Fixing use of useInstanceId
Dropping the old `useUniqueId` pattern in favour of the more succinct and complete `useInstanceId` usage.
  • Loading branch information
Andrew Hayward committed Jul 12, 2023
commit 9da368df18f970c2945fe4bd9ae29f758f5f368d
9 changes: 1 addition & 8 deletions packages/components/src/text-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ import BaseControl from '../base-control';
import type { WordPressComponentProps } from '../ui/context';
import type { TextControlProps } from './types';

function useUniqueId( idProp?: string ) {
const instanceId = useInstanceId( TextControl );
const id = `inspector-text-control-${ instanceId }`;

return idProp || id;
}

function UnforwardedTextControl(
props: WordPressComponentProps< TextControlProps, 'input', false >,
ref: ForwardedRef< HTMLInputElement >
Expand All @@ -39,7 +32,7 @@ function UnforwardedTextControl(
type = 'text',
...additionalProps
} = props;
const id = useUniqueId( idProp );
const id = useInstanceId( TextControl, 'inspector-text-control', idProp );
const onChangeValue = ( event: ChangeEvent< HTMLInputElement > ) =>
onChange( event.target.value );

Expand Down