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
4 changes: 3 additions & 1 deletion packages/@react-spectrum/s2/src/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,16 @@ export const ActionButton = forwardRef(function ActionButton(props: ActionButton
orientation = 'horizontal',
staticColor = props.staticColor,
isQuiet = props.isQuiet,
size = props.size || 'M'
size = props.size || 'M',
isDisabled
} = ctx || {};

let {isProgressVisible} = usePendingState(isPending);

return (
<RACButton
{...props}
isDisabled={props.isDisabled ?? isDisabled}
ref={domRef}
style={pressScale(domRef, props.UNSAFE_style)}
className={renderProps => (props.UNSAFE_className || '') + btnStyles({
Expand Down
65 changes: 65 additions & 0 deletions packages/@react-spectrum/s2/test/ActionButtonGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {ActionButton, ActionButtonGroup, Text} from '../src';
import {render} from '@react-spectrum/test-utils-internal';

describe('ActionButtonGroup', () => {

it('can disable all buttons from the group', async () => {
let {getAllByRole} = render(
<ActionButtonGroup isDisabled>
<ActionButton><Text slot="label">Bold</Text></ActionButton>
<ActionButton><Text slot="label">Italic</Text></ActionButton>
<ActionButton><Text slot="label">Underline</Text></ActionButton>
</ActionButtonGroup>
);


let buttons = getAllByRole('button');
expect(buttons[0]).toBeDisabled();
expect(buttons[1]).toBeDisabled();
expect(buttons[2]).toBeDisabled();
});

it('can set disable individually', async () => {
let {getAllByRole} = render(
<ActionButtonGroup>
<ActionButton isDisabled><Text slot="label">Bold</Text></ActionButton>
<ActionButton><Text slot="label">Italic</Text></ActionButton>
<ActionButton><Text slot="label">Underline</Text></ActionButton>
</ActionButtonGroup>
);


let buttons = getAllByRole('button');
expect(buttons[0]).toBeDisabled();
expect(buttons[1]).not.toBeDisabled();
expect(buttons[2]).not.toBeDisabled();
});

it('can override the group disable', async () => {
let {getAllByRole} = render(
<ActionButtonGroup isDisabled>
<ActionButton isDisabled={false}><Text slot="label">Bold</Text></ActionButton>
<ActionButton><Text slot="label">Italic</Text></ActionButton>
<ActionButton><Text slot="label">Underline</Text></ActionButton>
</ActionButtonGroup>
);


let buttons = getAllByRole('button');
expect(buttons[0]).not.toBeDisabled();
expect(buttons[1]).toBeDisabled();
expect(buttons[2]).toBeDisabled();
});
});
33 changes: 33 additions & 0 deletions packages/@react-spectrum/s2/test/ToggleButtonGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {render} from '@react-spectrum/test-utils-internal';
import {Text, ToggleButton, ToggleButtonGroup} from '../src';

describe('ToggleButtonGroup', () => {

it('can disable all buttons from the group', async () => {
let {getAllByRole} = render(
<ToggleButtonGroup isDisabled>
<ToggleButton id={1}><Text slot="label">Bold</Text></ToggleButton>
<ToggleButton id={2}><Text slot="label">Italic</Text></ToggleButton>
<ToggleButton id={3}><Text slot="label">Underline</Text></ToggleButton>
</ToggleButtonGroup>
);


let buttons = getAllByRole('radio');
expect(buttons[0]).toBeDisabled();
expect(buttons[1]).toBeDisabled();
expect(buttons[2]).toBeDisabled();
});
});
19 changes: 19 additions & 0 deletions packages/react-aria-components/test/SearchField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ describe('SearchField', () => {
expect(document.getElementById(input.getAttribute('aria-describedby'))).toHaveTextContent('Constraints not satisfied');
expect(document.activeElement).toBe(input);

expect(input.parentElement).toHaveAttribute('data-invalid');
expect(input.parentElement).toHaveAttribute('data-required');

await user.keyboard('Devon');

expect(input).toHaveAttribute('aria-describedby');
Expand All @@ -127,6 +130,22 @@ describe('SearchField', () => {
expect(input).not.toHaveAttribute('aria-describedby');
});

it('supports readonly', async () => {
let {getByRole} = render(
<form data-testid="form">
<SearchField isReadOnly>
<Label>Test</Label>
<Input />
<FieldError />
</SearchField>
</form>
);

let input = getByRole('searchbox');

expect(input.parentElement).toHaveAttribute('data-readonly');
});

it('should support form prop', () => {
let {getByRole} = render(
<TestSearchField form="test" />
Expand Down
26 changes: 25 additions & 1 deletion packages/react-aria-components/test/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,30 @@ describe('Select', () => {
expect(trigger).toHaveTextContent('Select an animal');
});

it('should support empty state', async () => {
let {getByTestId, getByRole} = render(
<Select data-testid="select" allowsEmptyCollection>
<Label>Favorite Animal</Label>
<Button>
<SelectValue />
</Button>
<Popover>
<ListBox aria-label="Test" renderEmptyState={() => 'No results'}>
{[]}
</ListBox>
</Popover>
</Select>
);
let selectTester = testUtilUser.createTester('Select', {root: getByTestId('select')});
await selectTester.open();

let listbox = getByRole('listbox');
expect(listbox).toHaveAttribute('data-empty', 'true');

let option = getByRole('option');
expect(option).toHaveTextContent('No results');
});

it('should support render props', async () => {
let {getByTestId} = render(
<Select data-testid="select">
Expand Down Expand Up @@ -644,7 +668,7 @@ describe('Select', () => {

let wrapper = getByTestId('select');
let selectTester = testUtilUser.createTester('Select', {root: wrapper});

let trigger = selectTester.trigger;
expect(trigger).toHaveTextContent('Dog and Kangaroo');

Expand Down
6 changes: 4 additions & 2 deletions packages/react-aria-components/test/ToggleButtonGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ describe('ToggleButtonGroup', () => {
});

it('should support horizontal keyboard navigation', async () => {
let {getAllByRole} = renderGroup();
let {getAllByRole, getByRole} = renderGroup();
expect(getByRole('radiogroup')).toHaveAttribute('aria-orientation', 'horizontal');
let radios = getAllByRole('radio');
await user.tab();
expect(document.activeElement).toBe(radios[0]);
Expand All @@ -155,7 +156,8 @@ describe('ToggleButtonGroup', () => {
});

it('should support vertical keyboard navigation', async () => {
let {getAllByRole} = renderGroup({orientation: 'vertical'});
let {getAllByRole, getByRole} = renderGroup({orientation: 'vertical'});
expect(getByRole('radiogroup')).toHaveAttribute('aria-orientation', 'vertical');
let radios = getAllByRole('radio');
await user.tab();
expect(document.activeElement).toBe(radios[0]);
Expand Down