Skip to content

Commit f6058df

Browse files
committed
docs(modal): recommend ref over css selector
1 parent 94c9a12 commit f6058df

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/modal/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ When a Modal opens, it automatically manages focus to ensure proper accessibilit
140140

141141
1. **`initialFocus` prop**: The specified element receives focus
142142
- String selector: `initialFocus="#submit-button"`
143-
- React ref: `initialFocus={submitButtonRef}`
143+
- React ref: `initialFocus={submitButtonRef}` (recommended over string selector for better type safety)
144144
2. **`autoFocus` attribute**: If any child element has the `autoFocus` attribute, that element receives focus
145145
3. **First focusable element**: If `initialFocus` is `"auto"` and no child element has the `autoFocus` attribute, the first focusable element receives focus
146146
4. **No focus**: If `initialFocus` is `null`, no automatic focus occurs

packages/modal/src/Modal/Modal.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export interface ModalProps
5252
* **Options:**
5353
* - `"auto"`: Automatically focuses the first focusable element in the modal
5454
* - `string`: CSS selector passed to `querySelector()` to specify an element
55-
* - `React.RefObject<HTMLElement>`: Reference to the element that should receive focus
55+
* - `React.RefObject<HTMLElement>`: Reference to the element that should receive focus. This is recommended over using a CSS selector for better type safety.
5656
* - `null`: Disables automatic focus management. Use sparingly - disabling focus management may create accessibility issues
5757
*
5858
* **Priority order:**
@@ -70,7 +70,7 @@ export interface ModalProps
7070
* </Modal>
7171
*
7272
* @example
73-
* // Using a ref
73+
* // Using a ref (recommended over selector)
7474
* const submitRef = useRef<HTMLButtonElement>(null);
7575
* <Modal initialFocus={submitRef}>
7676
* <button ref={submitRef}>Submit</button>

0 commit comments

Comments
 (0)