@@ -14,6 +14,7 @@ import {
14
14
} from ' docz'
15
15
import {
16
16
Button ,
17
+ CheckboxField ,
17
18
FormLayout ,
18
19
Modal ,
19
20
ModalBody ,
@@ -666,57 +667,61 @@ On top of that, the modal can adjust to the width of its content.
666
667
}}
667
668
</Playground >
668
669
669
- 👉 Please note the auto width may not function correctly in combination with
670
- other auto-layout mechanisms, e.g. the auto-width
671
- [ FormLayout] ( /components/form-layout#label-width ) . It's just too much
672
- magic that doesn't work together (yet?) 🎩.
670
+ ## Position
673
671
674
- 👉 Beware of horizontal FormLayout inside ` small ` modals. While automatic
675
- overflow handling comes to the rescue in this kind of scenario, you will be
676
- better off with the combination of auto-sized modal and horizontal FormLayout
677
- with a fixed label width (i.e. any other than ` auto ` , see the previous note).
672
+ Modal can be aligned either to the top or center of the screen.
678
673
679
674
<Playground >
680
675
{ () => {
681
676
const [modalOpen, setModalOpen] = React .useState (false );
677
+ const [modalPosition, setModalPosition] = React .useState (' center' );
682
678
const modalPrimaryButtonRef = React .useRef ();
683
679
const modalCloseButtonRef = React .useRef ();
684
680
return (
685
681
<>
686
682
<Button
687
- label = " Launch auto-with modal with a form"
688
- onClick = { () => setModalOpen (true )}
683
+ label = " Launch modal at center"
684
+ onClick = { () => {
685
+ setModalPosition (' center' );
686
+ setModalOpen (true );
687
+ }}
688
+ />
689
+ <Button
690
+ label = " Launch modal at top"
691
+ onClick = { () => {
692
+ setModalPosition (' top' );
693
+ setModalOpen (true );
694
+ }}
689
695
/>
690
696
<div >
691
697
{ modalOpen && (
692
698
<Modal
693
699
closeButtonRef = { modalCloseButtonRef }
700
+ position = { modalPosition }
694
701
primaryButtonRef = { modalPrimaryButtonRef }
695
- size = " auto"
696
702
>
697
703
<ModalHeader >
698
- <ModalTitle >Form inside modal </ModalTitle >
704
+ <ModalTitle >Delete the user? </ModalTitle >
699
705
<ModalCloseButton onClick = { () => setModalOpen (false )} />
700
706
</ModalHeader >
701
707
<ModalBody >
702
708
<ModalContent >
703
- <FormLayout fieldLayout = " horizontal" >
704
- <TextField label = " A form element" />
705
- <TextField label = " Another form element" />
706
- <TextField label = " Yet another one" />
707
- </FormLayout >
709
+ <p >
710
+ Do you really want to delete the user <code >admin</code >?
711
+ This cannot be undone.
712
+ </p >
708
713
</ModalContent >
709
714
</ModalBody >
710
715
<ModalFooter >
711
716
<Button
712
- color = " primary "
713
- label = " Save "
717
+ color = " danger "
718
+ label = " Delete "
714
719
onClick = { () => setModalOpen (false )}
715
720
ref = { modalPrimaryButtonRef }
716
721
/>
717
722
<Button
718
723
color = " secondary"
719
- label = " Cancel "
724
+ label = " Close "
720
725
onClick = { () => setModalOpen (false )}
721
726
priority = " outline"
722
727
ref = { modalCloseButtonRef }
@@ -730,61 +735,64 @@ with a fixed label width (i.e. any other than `auto`, see the previous note).
730
735
}}
731
736
</Playground >
732
737
733
- ## Position
738
+ ## Forms in Modals
734
739
735
- Modal can be aligned either to the top or center of the screen.
740
+ You can safely place a FormLayout into a Modal of any size, including the
741
+ auto-width Modal.
736
742
737
743
<Playground >
738
744
{ () => {
739
745
const [modalOpen, setModalOpen] = React .useState (false );
740
- const [modalPosition, setModalPosition ] = React .useState (' center ' );
746
+ const [agree, setAgree ] = React .useState (true );
741
747
const modalPrimaryButtonRef = React .useRef ();
742
748
const modalCloseButtonRef = React .useRef ();
743
749
return (
744
750
<>
745
751
<Button
746
- label = " Launch modal at center"
747
- onClick = { () => {
748
- setModalPosition (' center' );
749
- setModalOpen (true );
750
- }}
751
- />
752
- <Button
753
- label = " Launch modal at top"
754
- onClick = { () => {
755
- setModalPosition (' top' );
756
- setModalOpen (true );
757
- }}
752
+ label = " Launch auto-width modal with auto-width form"
753
+ onClick = { () => setModalOpen (true )}
758
754
/>
759
755
<div >
760
756
{ modalOpen && (
761
757
<Modal
762
758
closeButtonRef = { modalCloseButtonRef }
763
- position = { modalPosition }
764
759
primaryButtonRef = { modalPrimaryButtonRef }
760
+ size = " auto"
765
761
>
766
762
<ModalHeader >
767
- <ModalTitle >Delete the user? </ModalTitle >
763
+ <ModalTitle >Auto-width form inside auto-width modal </ModalTitle >
768
764
<ModalCloseButton onClick = { () => setModalOpen (false )} />
769
765
</ModalHeader >
770
766
<ModalBody >
771
767
<ModalContent >
772
- <p >
773
- Do you really want to delete the user <code >admin</code >?
774
- This cannot be undone.
775
- </p >
768
+ <FormLayout autoWidth fieldLayout = " horizontal" >
769
+ <TextField
770
+ label = " A form element"
771
+ validationState = " warning"
772
+ validationText = { ` Account with this name already exists,
773
+ pick a different one. `
774
+ }
775
+ />
776
+ <TextField label = " Another form element" />
777
+ <TextField label = " Yet another one" />
778
+ <CheckboxField
779
+ checked = { agree }
780
+ label = " I agree"
781
+ onChange = { () => setAgree (! agree )}
782
+ />
783
+ </FormLayout >
776
784
</ModalContent >
777
785
</ModalBody >
778
786
<ModalFooter >
779
787
<Button
780
- color = " danger "
781
- label = " Delete "
788
+ color = " primary "
789
+ label = " Save "
782
790
onClick = { () => setModalOpen (false )}
783
791
ref = { modalPrimaryButtonRef }
784
792
/>
785
793
<Button
786
794
color = " secondary"
787
- label = " Close "
795
+ label = " Cancel "
788
796
onClick = { () => setModalOpen (false )}
789
797
priority = " outline"
790
798
ref = { modalCloseButtonRef }
@@ -798,6 +806,14 @@ Modal can be aligned either to the top or center of the screen.
798
806
}}
799
807
</Playground >
800
808
809
+ 👉 Inside Modal, we recommend using the ` autoWidth ` option of FormLayout. This
810
+ prevents the Modal from unwanted horizontal expansion when a long validation
811
+ text pops up during user's interaction with the form.
812
+
813
+ 👉 Beware of horizontal FormLayout inside ` small ` modals. While automatic
814
+ overflow handling comes to the rescue in this kind of scenario, you will be
815
+ better off with the combination of auto-sized modal and horizontal FormLayout.
816
+
801
817
## Keyboard Control
802
818
803
819
Modal can be controlled either by mouse or keyboard. To enhance user
@@ -809,8 +825,8 @@ To enable it, you just need to pass a reference to the buttons using
809
825
a reference to the button is that if the button is disabled, the key press will
810
826
not fire the event.
811
827
812
- 👉 We strongly recommend using this feature together with Autofocus for a better
813
- user experience.
828
+ 👉 We strongly recommend using this feature together with
829
+ [ Autofocus ] ( #autofocus ) for a better user experience.
814
830
815
831
## Autofocus
816
832
0 commit comments