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

fix(Select): allow attachment of headlessUI props to label #1991

Merged
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
5 changes: 3 additions & 2 deletions src/components/FieldLabel/FieldLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type FieldLabelProps = {
/**
* ID of input that label is associated with.
*/
htmlFor: string;
htmlFor?: string;
// Design API
/**
* Indicates disabled state of the input.
Expand All @@ -36,7 +36,7 @@ export type FieldLabelProps = {
* Label associated with an input element or field.
*/
export const FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(
({ children, className, htmlFor, size = 'lg', disabled }, ref) => {
({ children, className, htmlFor, size = 'lg', disabled, ...other }, ref) => {
const componentClassName = clsx(
styles['label'],
size === 'md' && styles['label--md'],
Expand All @@ -50,6 +50,7 @@ export const FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(
className={componentClassName}
htmlFor={htmlFor}
ref={ref}
{...other}
>
{children}
</label>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Select/Select-v2.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('<Select />', () => {
onChange={() => undefined}
value={exampleOptions[0]}
>
<Select.Label htmlFor="non-throwing-select">Options:</Select.Label>
<Select.Label>Options:</Select.Label>
<Select.Button>Select</Select.Button>

<Select.Options>
Expand Down
9 changes: 0 additions & 9 deletions src/components/Select/Select-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import React, {
import { createPortal } from 'react-dom';
import { usePopper } from 'react-popper';

import { useId } from '../../util/useId';
import type { ExtractProps } from '../../util/utility-types';
import type { Status } from '../../util/variant-types';
import FieldLabel from '../FieldLabel';
Expand Down Expand Up @@ -89,7 +88,6 @@ type SelectProps = ExtractProps<typeof Listbox> &

type SelectLabelProps = ExtractProps<typeof Listbox.Label> & {
disabled?: boolean;
htmlFor: string;
required?: boolean;
showHint?: boolean;
};
Expand Down Expand Up @@ -231,9 +229,6 @@ export function Select({
other.value !== undefined ? other.value : other.defaultValue,
);

const generatedIdVar = useId();
const idVar = id || generatedIdVar;

const componentClassName = clsx(
styles['select'],
fieldNote && styles['select--has-fieldNote'],
Expand All @@ -247,7 +242,6 @@ export function Select({
// Otherwise we get an error.
as: 'div' as const,
disabled,
id: idVar,
name,
...other,
};
Expand Down Expand Up @@ -293,7 +287,6 @@ export function Select({
{(label || required) && (
<Select.Label
disabled={disabled}
htmlFor={idVar}
required={required}
showHint={showHint}
>
Expand All @@ -318,7 +311,6 @@ const SelectLabel = ({
required,
className,
disabled,
htmlFor,
showHint,
}: SelectLabelProps) => {
const componentClassName = clsx(
Expand All @@ -343,7 +335,6 @@ const SelectLabel = ({
as={FieldLabel}
className={componentClassName}
disabled={disabled}
htmlFor={htmlFor}
>
{label}
</Listbox.Label>
Expand Down
Loading
Loading