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
9 changes: 8 additions & 1 deletion packages/@react-aria/select/src/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
let valueId = useId();

return {
labelProps,
labelProps: {
...labelProps,
onClick: () => {
if (!props.isDisabled) {
ref.current.focus();
}
}
},
triggerProps: mergeProps(domProps, {
...triggerProps,
'aria-labelledby': [
Expand Down
2 changes: 2 additions & 0 deletions packages/@react-spectrum/label/src/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Label(props: SpectrumLabelProps, ref: DOMRef<HTMLLabelElement>) {
htmlFor,
for: labelFor,
elementType: ElementType = 'label',
onClick,
...otherProps
} = props;

Expand Down Expand Up @@ -63,6 +64,7 @@ function Label(props: SpectrumLabelProps, ref: DOMRef<HTMLLabelElement>) {
<ElementType
{...filterDOMProps(otherProps)}
{...styleProps}
onClick={onClick}
ref={domRef}
className={labelClassNames}
htmlFor={ElementType === 'label' ? labelFor || htmlFor : undefined}>
Expand Down
18 changes: 18 additions & 0 deletions packages/@react-spectrum/picker/test/Picker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,24 @@ describe('Picker', function () {
});

describe('labeling', function () {
it('focuses on the picker when you click the label', function () {
let {getAllByText, getByRole} = render(
<Provider theme={theme}>
<Picker label="Test" onSelectionChange={onSelectionChange}>
<Item>One</Item>
<Item>Two</Item>
<Item>Three</Item>
</Picker>
</Provider>
);

let label = getAllByText('Test')[0];
label.click();

let picker = getByRole('button');
expect(document.activeElement).toBe(picker);
});

it('supports labeling with a visible label', function () {
let {getAllByText, getByText, getByRole} = render(
<Provider theme={theme}>
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-types/label/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import {Alignment, DOMProps, LabelPosition, NecessityIndicator, StyleProps} from '@react-types/shared';
import {ElementType, ReactNode} from 'react';
import {ElementType, HTMLAttributes, ReactNode} from 'react';

export interface LabelProps {
children?: ReactNode,
Expand All @@ -20,7 +20,7 @@ export interface LabelProps {
elementType?: ElementType
}

export interface SpectrumLabelProps extends LabelProps, DOMProps, StyleProps {
export interface SpectrumLabelProps extends LabelProps, DOMProps, StyleProps, HTMLAttributes<HTMLElement> {
labelPosition?: LabelPosition, // default top
labelAlign?: Alignment, // default start
isRequired?: boolean,
Expand Down