4141import gwt .material .design .client .base .MaterialWidget ;
4242import gwt .material .design .client .base .mixin .CssNameMixin ;
4343import gwt .material .design .client .constants .Axis ;
44+ import gwt .material .design .client .js .Window ;
4445import gwt .material .design .client .ui .MaterialLoader ;
4546import gwt .material .design .client .ui .animate .MaterialAnimator ;
4647import gwt .material .design .client .ui .animate .Transition ;
@@ -92,6 +93,8 @@ public class MaterialStepper extends MaterialWidget implements HasAxis, HasError
9293 private Div divFeedback = new Div ();
9394 private Span feedbackSpan = new Span ();
9495 private boolean stepSkippingAllowed = true ;
96+ private boolean detectOrientation = false ;
97+ protected HandlerRegistration orientationHandler ;
9598
9699 private final CssNameMixin <MaterialStepper , Axis > axisMixin = new CssNameMixin <>(this );
97100
@@ -111,6 +114,34 @@ protected void onLoad() {
111114 }
112115 }
113116
117+ public void setDetectOrientation (boolean detectOrientation ) {
118+ this .detectOrientation = detectOrientation ;
119+
120+ if (orientationHandler != null ) {
121+ orientationHandler .removeHandler ();
122+ orientationHandler = null ;
123+ }
124+
125+ if (detectOrientation ) {
126+ orientationHandler = com .google .gwt .user .client .Window .addResizeHandler (resizeEvent -> {
127+ detectAndApplyOrientation ();
128+ });
129+ detectAndApplyOrientation ();
130+ }
131+ }
132+
133+ protected void detectAndApplyOrientation () {
134+ if (Window .matchMedia ("(orientation: portrait)" )) {
135+ setAxis (Axis .VERTICAL );
136+ } else {
137+ setAxis (Axis .HORIZONTAL );
138+ }
139+ }
140+
141+ public boolean isDetectOrientation () {
142+ return detectOrientation ;
143+ }
144+
114145 /**
115146 * Specific method to add {@link MaterialStep}s to the stepper.
116147 */
0 commit comments