5

Is there a way to create a Box or a Paper with a title on top like this screenshot : enter image description here

I'm talking about the top lefty title portion. I tried using a Box or a Paper component but it doesn't seem like the option is there.

Thank you for the help

Steve
  • 11,596
  • 7
  • 39
  • 53

1 Answers1

9

You can change a Box's underlying element to a fieldset and add a legend element as a child of the MUI Box, but you'll probably want to apply a little styling to it as MUI does not offer styled versions of fieldset/legend.

import React from "react";
import Box from "@mui/material/Box";

const FieldsetExample = () => {
  return (
    <Box component="fieldset">
      <legend>Jean-François H</legend>
      Box content goes here.
    </Box>
  );
}

Renders:
Rendered fieldset code

Working CodeSandbox:
https://codesandbox.io/s/nostalgic-booth-09dwu7?file=/demo.js

Documentation References:
MUI Docs - Box API props (see component)
MDN Docs - <fieldset>: The Field Set element

Steve
  • 11,596
  • 7
  • 39
  • 53
  • 1
    FYI This should work for MUI 4 as well (you didn't specify a version) with just a change of the imports. – Steve Oct 12 '22 at 06:21
  • 1
    Wow thank you so much for that. It's exactly what I was looking for. How the heck did you figure that out? I've been looking for the past day for that kind of information on MUI docs! – Jean-François Handfield Oct 12 '22 at 12:42
  • Haha I work with the Box `component` prop a lot (for accessibility), and I just happened to recognize the `fieldset` element from your picture. Glad I could help! :D – Steve Oct 12 '22 at 15:49