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

[Joy] Miscellaneous fixes #35345

Merged
merged 7 commits into from
Dec 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/mui-joy/src/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,15 @@ const AutocompleteWrapper = styled('div', {
alignItems: 'center',
flexWrap: 'wrap',
[`&.${autocompleteClasses.multiple}`]: {
paddingInlineStart: 0,
paddingBlockStart:
'calc(var(--_Input-paddingBlock) - max(var(--Autocomplete-wrapper-gap), 0px))',
paddingBlockEnd: 'var(--_Input-paddingBlock)',
paddingBlockEnd: 'min(var(--_Input-paddingBlock), var(--Autocomplete-wrapper-gap))',
// TODO: use [CSS :has](https://caniuse.com/?search=%3Ahas) later
...(ownerState.startDecorator &&
Array.isArray(ownerState.value) &&
(ownerState.value as Array<unknown>).length > 0 && {
marginBlockStart: 'min(var(--_Input-paddingBlock) - var(--Autocomplete-wrapper-gap), 0px)',
marginInlineStart:
'calc(-1 * min(var(--Autocomplete-wrapper-gap), var(--_Input-paddingBlock)))',
marginInlineStart: 'calc(-1 * var(--Autocomplete-wrapper-gap))',
[`& .${autocompleteClasses.input}`]: {
marginInlineStart: 'var(--Input-gap)',
marginInlineStart: 'max(var(--Autocomplete-wrapper-gap), var(--Input-gap))',
},
}),
},
Expand Down Expand Up @@ -484,7 +480,7 @@ const Autocomplete = React.forwardRef(function Autocomplete(
name,
readOnly,
disabled,
required,
required: required ?? formControl?.required,
type,
'aria-invalid': error || undefined,
'aria-label': ariaLabel,
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-joy/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const ButtonRoot = styled('button', {
transition:
'background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
fontFamily: theme.vars.fontFamily.body,
fontWeight: theme.vars.fontWeight.md,
fontWeight: theme.vars.fontWeight.lg,
lineHeight: 1,
...(ownerState.fullWidth && {
width: '100%',
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-joy/src/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) {
name,
value,
readOnly,
required,
required: required ?? formControl?.required,
'aria-describedby': formControl?.['aria-describedby'],
...(indeterminate && {
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-checked#values
Expand Down
53 changes: 53 additions & 0 deletions packages/mui-joy/src/FormControl/FormControl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ describe('<FormControl />', () => {

expect(getByRole('textbox')).to.have.attribute('disabled');
});

it('should inherit required from FormControl', () => {
const { getByRole } = render(
<FormControl required>
<FormLabel>label</FormLabel>
<Input />
</FormControl>,
);

expect(getByRole('textbox')).to.have.attribute('required');
});
});

describe('Textarea', () => {
Expand Down Expand Up @@ -139,6 +150,17 @@ describe('<FormControl />', () => {

expect(getByLabelText('label')).to.have.attribute('disabled');
});

it('should inherit required from FormControl', () => {
const { getByRole } = render(
<FormControl required>
<FormLabel>label</FormLabel>
<Textarea minRows={2} />
</FormControl>,
);

expect(getByRole('textbox', { name: 'label' })).to.have.attribute('required');
});
});

describe('Select', () => {
Expand Down Expand Up @@ -242,6 +264,16 @@ describe('<FormControl />', () => {
expect(getByTestId('checkbox')).to.have.class(checkboxClasses.disabled);
expect(getByLabelText('label')).to.have.attribute('disabled');
});

it('should inherit required from FormControl', () => {
const { getByLabelText } = render(
<FormControl required>
<Checkbox label="label" data-testid="checkbox" />
</FormControl>,
);

expect(getByLabelText('label')).to.have.attribute('required');
});
});

describe('RadioGroup', () => {
Expand Down Expand Up @@ -328,6 +360,16 @@ describe('<FormControl />', () => {
expect(getByTestId('radio')).to.have.class(radioClasses.disabled);
expect(getByLabelText('label')).to.have.attribute('disabled');
});

it('should inherit required from FormControl', () => {
const { getByLabelText } = render(
<FormControl required>
<Radio label="label" data-testid="radio" />
</FormControl>,
);

expect(getByLabelText('label')).to.have.attribute('required');
});
});

describe('Switch', () => {
Expand Down Expand Up @@ -420,5 +462,16 @@ describe('<FormControl />', () => {

expect(getByRole('combobox')).to.have.attribute('disabled');
});

it('should inherit required from FormControl', () => {
const { getByRole } = render(
<FormControl disabled>
<FormLabel>label</FormLabel>
<Autocomplete options={[]} />
</FormControl>,
);

expect(getByRole('combobox')).to.have.attribute('disabled');
});
});
});
7 changes: 7 additions & 0 deletions packages/mui-joy/src/Input/Input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ describe('Joy <Input />', () => {
expect(screen.getByTestId('end')).toBeVisible();
});

describe('prop: required', () => {
it('should pass to `input` element', () => {
const { getByRole } = render(<Input required />);
expect(getByRole('textbox')).to.have.attribute('required');
});
});

describe('prop: disabled', () => {
it('should have disabled classes', () => {
const { container, getByRole } = render(<Input disabled />);
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-joy/src/Input/useForwardedInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function useForwardedInput<Output>(
onClick,
onChange,
onFocus,
required,
required: required ?? formControl?.required,
value,
});

Expand Down
12 changes: 12 additions & 0 deletions packages/mui-joy/src/Link/Link.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import { spy } from 'sinon';
import { act, createRenderer, fireEvent, describeConformance } from 'test/utils';
import Link, { linkClasses as classes } from '@mui/joy/Link';
import Typography from '@mui/joy/Typography';
import { ThemeProvider } from '@mui/joy/styles';
import { unstable_capitalize as capitalize } from '@mui/utils';

Expand Down Expand Up @@ -183,4 +184,15 @@ describe('<Link />', () => {
});
});
});

describe('Typography', () => {
it('should be a span by default', () => {
const { container } = render(
<Link href="/">
hello <Typography>test</Typography>
</Link>,
);
expect(container.querySelector('span')).to.have.text('test');
});
});
});
14 changes: 9 additions & 5 deletions packages/mui-joy/src/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,16 @@ const Link = React.forwardRef(function Link(inProps, ref) {
});

return (
<LinkRoot {...rootProps}>
{startDecorator && <StartDecorator {...startDecoratorProps}>{startDecorator}</StartDecorator>}
<TypographyContext.Provider value>
<LinkRoot {...rootProps}>
{startDecorator && (
<StartDecorator {...startDecoratorProps}>{startDecorator}</StartDecorator>
)}

{children}
{endDecorator && <EndDecorator {...endDecoratorProps}>{endDecorator}</EndDecorator>}
</LinkRoot>
{children}
{endDecorator && <EndDecorator {...endDecoratorProps}>{endDecorator}</EndDecorator>}
</LinkRoot>
</TypographyContext.Provider>
);
}) as OverridableComponent<LinkTypeMap>;

Expand Down
2 changes: 1 addition & 1 deletion packages/mui-joy/src/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
id,
name,
readOnly,
required,
required: required ?? formControl?.required,
value: String(value),
'aria-describedby': formControl?.['aria-describedby'],
},
Expand Down
3 changes: 3 additions & 0 deletions packages/mui-joy/src/Slider/sliderClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface SliderClasses {
disabled: string;
/** State class applied to the root if a thumb is being dragged. */
dragging: string;
/** State class applied to the thumb element if it has keyboard focused. */
focusVisible: string;
/** Class name applied to the rail element. */
rail: string;
/** Class name applied to the track element. */
Expand Down Expand Up @@ -61,6 +63,7 @@ const sliderClasses: SliderClasses = generateUtilityClasses('JoySlider', [
'root',
'disabled',
'dragging',
'focusVisible',
'marked',
'vertical',
'trackInverted',
Expand Down