admin管理员组

文章数量:1278760

I’m using Fluent UI to build a Pivot component with a form inside, with the goal of having multiple fields across different pivots, similar to the example in this image: tabbed form

However, I'm encountering an issue where the form fields get reset every time the pivot is changed. This is unexpected behavior, as I want the form fields to retain their values even when switching between tabs.

const {
  Fabric,
  Pivot,
  PivotItem,
  TextField,
  PrimaryButton,
  Stack
} = window.FluentUIReact;


const Demo = () => {  
  return (
    <Fabric>
     <form>
      <Pivot aria-label="Basic Pivot Example">
        <PivotItem headerText="My Files">
            <Stack tokens={{ childrenGap: 10 }}>
              <TextField label="Name" required />
              <TextField label="Email" type="email" required />
              <PrimaryButton text="Submit" onClick={() => alert('Form submitted!')} />
            </Stack>
        </PivotItem>
        <PivotItem headerText="Recent">
          Pivot #2
        </PivotItem>
        <PivotItem headerText="Shared with me">
          Pivot #3
        </PivotItem>
      </Pivot>
      </form>

    </Fabric>
  );
}

ReactDOM.render(<Demo />, document.getElementById('container'));

Tired to persist the form values to manage state using React's useState hook.

本文标签: reactjsFluentUI Form Fields Resetting When Pivot ChangesStack Overflow