Skip to content

Conversation

acmertz
Copy link
Contributor

@acmertz acmertz commented Nov 17, 2022

WHY are these changes introduced?

Fixes #7728

WHAT is this pull request doing?

Adds the disabled attribute to the <button> element that is rendered by UnstyledButton to prevent it from being selected by button:not(:disabled) CSS selectors.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
import React, {useState} from 'react';

import {Button, Modal, Page, Stack, TextField} from '../src';

export function Playground() {
  const [isModalOpen, setIsModalOpen] = useState(false);

  function handleClose() {
    setIsModalOpen(false);
  }

  function noop() {}

  return (
    <Page title="Playground">
      <Button onClick={() => setIsModalOpen(true)}>Open modal</Button>
      <Button disabled>Disabled button</Button>

      <Modal
        open={isModalOpen}
        onClose={handleClose}
        title="Example modal"
        primaryAction={{
          content: 'Primary action',
          onAction: handleClose,
          disabled: true,
        }}
      >
        <Modal.Section>
          <Stack vertical>
            <p>Some content</p>
            <TextField
              onChange={noop}
              autoComplete=""
              label="Text field 1"
              value=""
            />
            <TextField
              onChange={noop}
              autoComplete=""
              label="Text field 2"
              value=""
            />
          </Stack>
        </Modal.Section>
      </Modal>
    </Page>
  );
}
  1. Copy the above code into Playground.tsx and run yarn dev
  2. Confirm that the button labeled "Disabled button" has the disabled attribute
  3. Confirm that this fixes [Modal] Focus isn't trapped in the modal when the primary action is disabled #7728:
    1. Click "Open modal"
    2. Use the Tab key to cycle through focusable elements within the modal
    3. Confirm that focus wraps around to the beginning of the modal despite the primary action button being disabled

🎩 checklist

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
polaris-react-cjs 210.4 KB (+0.01% 🔺)
polaris-react-esm 136.15 KB (+0.01% 🔺)
polaris-react-esnext 191.7 KB (+0.01% 🔺)
polaris-react-css 41.81 KB (0%)

@acmertz acmertz marked this pull request as ready for review November 17, 2022 16:43
@yurm04 yurm04 requested review from mrcthms and zakwarsame and removed request for mrcthms November 17, 2022 19:38
@acmertz
Copy link
Contributor Author

acmertz commented Nov 18, 2022

Closing in favor of #7760

@acmertz acmertz closed this Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Modal] Focus isn't trapped in the modal when the primary action is disabled
1 participant