@@ -159,6 +159,10 @@ React.createElement(() => {
159
159
label="Launch modal as form"
160
160
onClick={() => setModalOpen(4)}
161
161
/>
162
+ <Button
163
+ label="Launch modal as native form"
164
+ onClick={() => setModalOpen(5)}
165
+ />
162
166
<div>
163
167
{modalOpen === 1 && (
164
168
<Modal>
@@ -278,6 +282,91 @@ React.createElement(() => {
278
282
</ModalFooter>
279
283
</Modal>
280
284
)}
285
+ {modalOpen === 5 && (
286
+ <Modal
287
+ allowPrimaryActionOnEnterKey={false}
288
+ closeButtonRef={modalCloseButtonRef}
289
+ onCancel={(e) => {
290
+ console.log('cancel', e);
291
+ }}
292
+ onClose={(e) => {
293
+ console.log('close', e);
294
+ }}
295
+ primaryButtonRef={modalPrimaryButtonRef}
296
+ >
297
+ <ModalHeader>
298
+ <ModalTitle>Add new user using native form</ModalTitle>
299
+ <ModalCloseButton onClick={() => setModalOpen(false)} />
300
+ </ModalHeader>
301
+ <ModalBody>
302
+ <ModalContent>
303
+ <p>
304
+ This is an example of a native form inside a modal.
305
+ The difference is that the dialog is not controlled by React UI,
306
+ but using native <code><form></code> element.
307
+ This is useful when you need to use native form features
308
+ like validation, submission, etc.
309
+ </p>
310
+ <p>
311
+ First, you need to set <code>allowPrimaryActionOnEnterKey</code>
312
+ to <code>false</code> and remove <code>onClick</code> from the
313
+ primary button. Then, you need to set <code>form</code> attribute
314
+ on the primary button to the <code>id</code> of the form to
315
+ connect it with the form.
316
+ </p>
317
+ <p>
318
+ Although we do not encourage using this approach, it is still
319
+ possible to use it when needed.
320
+ </p>
321
+ <hr />
322
+ <form method="dialog" id="native-form">
323
+ <FormLayout fieldLayout="horizontal" labelWidth="limited">
324
+ <Toggle
325
+ label="Enabled"
326
+ />
327
+ <TextField label="Username" required />
328
+ <TextField label="Password" type="password" />
329
+ <CheckboxField label="Force password on login" />
330
+ <Radio
331
+ label="Type of collaboration"
332
+ options={[
333
+ { label: 'Internal', value: 'internal'},
334
+ { label: 'External', value: 'external'},
335
+ ]}
336
+ />
337
+ <SelectField
338
+ label="Role"
339
+ options={[
340
+ { label: 'Programmer', value: 'programmer' },
341
+ { label: 'Team leader', value: 'team-leader' },
342
+ { label: 'Project manager', value: 'project-manager' },
343
+ ]}
344
+ />
345
+ <FileInputField label="Photo" />
346
+ <TextArea
347
+ label="Additional info"
348
+ helpText={<p>Enter key is used for new line,<br />so <strong>Enter won't submit the form</strong>.</p>}
349
+ />
350
+ </FormLayout>
351
+ </form>
352
+ </ModalContent>
353
+ </ModalBody>
354
+ <ModalFooter>
355
+ <Button
356
+ form="native-form"
357
+ label="Save"
358
+ ref={modalPrimaryButtonRef}
359
+ type="submit"
360
+ />
361
+ <Button
362
+ label="Close"
363
+ onClick={() => setModalOpen(false)}
364
+ priority="outline"
365
+ ref={modalCloseButtonRef}
366
+ />
367
+ </ModalFooter>
368
+ </Modal>
369
+ )}
281
370
</div>
282
371
</RUIProvider>
283
372
);
0 commit comments