Skip to content

Commit 4d8f9b8

Browse files
github-actions[bot]siriwatknpsai6855
authored
[material-ui][OutlinedInput] Add missing notchedOutline slot (@siriwatknp) (#45938)
Co-authored-by: Siriwat K <[email protected]> Co-authored-by: sai chand <[email protected]>
1 parent dec2a4b commit 4d8f9b8

File tree

6 files changed

+108
-24
lines changed

6 files changed

+108
-24
lines changed

docs/pages/material-ui/api/outlined-input.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@
4242
"readOnly": { "type": { "name": "bool" } },
4343
"required": { "type": { "name": "bool" } },
4444
"rows": { "type": { "name": "union", "description": "number<br>&#124;&nbsp;string" } },
45+
"slotProps": {
46+
"type": {
47+
"name": "shape",
48+
"description": "{ input?: object, notchedOutline?: func<br>&#124;&nbsp;object, root?: object }"
49+
},
50+
"default": "{}"
51+
},
4552
"slots": {
46-
"type": { "name": "shape", "description": "{ input?: elementType, root?: elementType }" },
53+
"type": {
54+
"name": "shape",
55+
"description": "{ input?: elementType, notchedOutline?: elementType, root?: elementType }"
56+
},
4757
"default": "{}"
4858
},
4959
"startAdornment": { "type": { "name": "node" } },

docs/translations/api-docs/outlined-input/outlined-input.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@
6868
"description": "If <code>true</code>, the <code>input</code> element is required. The prop defaults to the value (<code>false</code>) inherited from the parent FormControl component."
6969
},
7070
"rows": { "description": "Number of rows to display when multiline option is set to true." },
71-
"slots": {
72-
"description": "The components used for each slot inside.<br>This prop is an alias for the <code>components</code> prop, which will be deprecated in the future."
73-
},
71+
"slotProps": { "description": "The props used for each slot inside." },
72+
"slots": { "description": "The components used for each slot inside." },
7473
"startAdornment": { "description": "Start <code>InputAdornment</code> for this component." },
7574
"sx": {
7675
"description": "The system prop that allows defining system overrides as well as additional CSS styles."

packages/mui-material/src/OutlinedInput/OutlinedInput.d.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
import * as React from 'react';
22
import { SxProps } from '@mui/system';
3-
import { InternalStandardProps as StandardProps, Theme } from '..';
3+
import {
4+
CreateSlotsAndSlotProps,
5+
SlotProps,
6+
InternalStandardProps as StandardProps,
7+
Theme,
8+
} from '..';
49
import { InputBaseProps } from '../InputBase';
510
import { OutlinedInputClasses } from './outlinedInputClasses';
611

7-
export interface OutlinedInputProps extends StandardProps<InputBaseProps> {
12+
interface OutlinedInputSlots {
13+
/**
14+
* The component that renders the notchedOutline slot.
15+
* @default NotchedOutline
16+
*/
17+
notchedOutline: React.ElementType;
18+
}
19+
20+
type OutlinedInputSlotsAndSlotProps = CreateSlotsAndSlotProps<
21+
OutlinedInputSlots,
22+
{
23+
notchedOutline: SlotProps<'fieldset', {}, OutlinedInputOwnerState>;
24+
}
25+
> & {
26+
slots?: InputBaseProps['slots'];
27+
slotProps?: InputBaseProps['slotProps'];
28+
};
29+
30+
export interface OutlinedInputProps
31+
extends Omit<StandardProps<InputBaseProps>, 'slots' | 'slotProps'>,
32+
OutlinedInputSlotsAndSlotProps {
833
/**
934
* Override or extend the styles applied to the component.
1035
*/
@@ -24,6 +49,8 @@ export interface OutlinedInputProps extends StandardProps<InputBaseProps> {
2449
sx?: SxProps<Theme>;
2550
}
2651

52+
export interface OutlinedInputOwnerState extends Omit<OutlinedInputProps, 'slots' | 'slotProps'> {}
53+
2754
/**
2855
*
2956
* Demos:

packages/mui-material/src/OutlinedInput/OutlinedInput.js

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import InputBase, {
1818
InputBaseRoot,
1919
InputBaseInput,
2020
} from '../InputBase/InputBase';
21+
import useSlot from '../utils/useSlot';
2122

2223
const useUtilityClasses = (ownerState) => {
2324
const { classes } = ownerState;
@@ -197,6 +198,7 @@ const OutlinedInput = React.forwardRef(function OutlinedInput(inProps, ref) {
197198
multiline = false,
198199
notched,
199200
slots = {},
201+
slotProps = {},
200202
type = 'text',
201203
...other
202204
} = props;
@@ -227,23 +229,35 @@ const OutlinedInput = React.forwardRef(function OutlinedInput(inProps, ref) {
227229
const RootSlot = slots.root ?? components.Root ?? OutlinedInputRoot;
228230
const InputSlot = slots.input ?? components.Input ?? OutlinedInputInput;
229231

232+
const [NotchedSlot, notchedProps] = useSlot('notchedOutline', {
233+
elementType: NotchedOutlineRoot,
234+
className: classes.notchedOutline,
235+
shouldForwardComponentProp: true,
236+
ownerState,
237+
externalForwardedProps: {
238+
slots,
239+
slotProps,
240+
},
241+
additionalProps: {
242+
label:
243+
label != null && label !== '' && fcs.required ? (
244+
<React.Fragment>
245+
{label}
246+
&thinsp;{'*'}
247+
</React.Fragment>
248+
) : (
249+
label
250+
),
251+
},
252+
});
253+
230254
return (
231255
<InputBase
232256
slots={{ root: RootSlot, input: InputSlot }}
257+
slotProps={slotProps}
233258
renderSuffix={(state) => (
234-
<NotchedOutlineRoot
235-
ownerState={ownerState}
236-
className={classes.notchedOutline}
237-
label={
238-
label != null && label !== '' && fcs.required ? (
239-
<React.Fragment>
240-
{label}
241-
&thinsp;{'*'}
242-
</React.Fragment>
243-
) : (
244-
label
245-
)
246-
}
259+
<NotchedSlot
260+
{...notchedProps}
247261
notched={
248262
typeof notched !== 'undefined'
249263
? notched
@@ -404,15 +418,22 @@ OutlinedInput.propTypes /* remove-proptypes */ = {
404418
* Number of rows to display when multiline option is set to true.
405419
*/
406420
rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
421+
/**
422+
* The props used for each slot inside.
423+
* @default {}
424+
*/
425+
slotProps: PropTypes.shape({
426+
input: PropTypes.object,
427+
notchedOutline: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
428+
root: PropTypes.object,
429+
}),
407430
/**
408431
* The components used for each slot inside.
409-
*
410-
* This prop is an alias for the `components` prop, which will be deprecated in the future.
411-
*
412432
* @default {}
413433
*/
414434
slots: PropTypes.shape({
415435
input: PropTypes.elementType,
436+
notchedOutline: PropTypes.elementType,
416437
root: PropTypes.elementType,
417438
}),
418439
/**
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import OutlinedInput from '@mui/material/OutlinedInput';
3+
4+
function NoNotched() {
5+
return null;
6+
}
7+
8+
<OutlinedInput
9+
slots={{
10+
notchedOutline: NoNotched,
11+
}}
12+
/>;
13+
<OutlinedInput
14+
slotProps={{
15+
notchedOutline: {
16+
className: 'hidden',
17+
},
18+
}}
19+
/>;

packages/mui-material/src/OutlinedInput/OutlinedInput.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import describeConformance from '../../test/describeConformance';
99
describe('<OutlinedInput />', () => {
1010
const { render } = createRenderer();
1111

12-
describeConformance(<OutlinedInput />, () => ({
12+
const CustomNotchedOutline = React.forwardRef(({ notched, ownerState, ...props }, ref) => (
13+
<i ref={ref} data-testid="custom" {...props} />
14+
));
15+
16+
describeConformance(<OutlinedInput label="Label" />, () => ({
1317
classes,
1418
inheritComponent: InputBase,
1519
render,
@@ -18,11 +22,15 @@ describe('<OutlinedInput />', () => {
1822
testDeepOverrides: { slotName: 'input', slotClassName: classes.input },
1923
testVariantProps: { variant: 'contained', fullWidth: true },
2024
testStateOverrides: { prop: 'size', value: 'small', styleKey: 'sizeSmall' },
21-
testLegacyComponentsProp: true,
25+
testLegacyComponentsProp: ['root', 'input'],
2226
slots: {
2327
// can't test with DOM element as InputBase places an ownerState prop on it unconditionally.
2428
root: { expectedClassName: classes.root, testWithElement: null },
2529
input: { expectedClassName: classes.input, testWithElement: null },
30+
notchedOutline: {
31+
expectedClassName: classes.notchedOutline,
32+
testWithElement: CustomNotchedOutline,
33+
},
2634
},
2735
skip: [
2836
'componentProp',

0 commit comments

Comments
 (0)