@@ -101,36 +101,70 @@ class Stepper extends CollectionWidgetAsync<StepperProperties> {
101101 return icon ;
102102 }
103103
104- _prepareDefaultItemTemplate ( data : Item , $container : dxElementWrapper ) : void {
105- const { text, title , optional } = data ;
104+ _getStepIndicator ( data : Item ) : dxElementWrapper {
105+ const { text } = data ;
106106
107107 const $indicatorElement = $ ( '<div>' ) . addClass ( STEP_INDICATOR_CLASS ) ;
108108
109109 const iconName = this . _getStepIcon ( data ) ;
110- const $iconElement = getImageContainer ( iconName ) ?? $ ( '<div>' ) . addClass ( STEP_TEXT_CLASS ) . text ( text ?? '' ) ;
110+ const $indicatorContent = getImageContainer ( iconName ) ?? $ ( '<div>' ) . addClass ( STEP_TEXT_CLASS ) . text ( text ?? '' ) ;
111111
112- $iconElement . appendTo ( $indicatorElement ) ;
112+ $indicatorElement . append ( $indicatorContent ) ;
113113
114- $indicatorElement . prependTo ( $container ) ;
114+ return $indicatorElement ;
115+ }
115116
116- const hasTitle = isDefined ( title ) ;
117- const hasLabel = hasTitle || optional ;
117+ _getStepTitle ( data : Item ) : dxElementWrapper {
118+ const { title } = data ;
118119
119- if ( hasLabel ) {
120- const $stepLabel = $ ( '<div>' ) . addClass ( STEP_LABEL_CLASS ) ;
121- const $stepTitle = hasTitle ? $ ( '<div>' ) . addClass ( STEP_TITLE_CLASS ) . text ( title ) : null ;
122- const $stepOptionalMark = optional
123- ? $ ( '<div>' ) . addClass ( STEP_OPTIONAL_MARK_CLASS ) . text ( messageLocalization . format ( 'dxStepper-optionalMark' ) )
124- : null ;
120+ if ( isDefined ( title ) ) {
121+ return $ ( '<div>' )
122+ . addClass ( STEP_TITLE_CLASS )
123+ . text ( title ) ;
124+ }
125+
126+ return $ ( ) ;
127+ }
125128
126- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
127- $stepTitle && $stepLabel . prepend ( $stepTitle ) ;
129+ _getStepOptionalMark ( data : Item ) : dxElementWrapper {
130+ const { optional } = data ;
128131
129- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
130- $stepOptionalMark && $stepLabel . append ( $stepOptionalMark ) ;
132+ if ( optional ) {
133+ const optionalMarkText = messageLocalization . format ( 'dxStepper-optionalMark' ) ;
131134
132- $stepLabel . appendTo ( $container ) ;
135+ return $ ( '<div>' )
136+ . addClass ( STEP_OPTIONAL_MARK_CLASS )
137+ . text ( optionalMarkText ) ;
133138 }
139+
140+ return $ ( ) ;
141+ }
142+
143+ _getStepLabel ( data : Item ) : dxElementWrapper {
144+ const $stepTitle = this . _getStepTitle ( data ) ;
145+ const $stepOptionalMark = this . _getStepOptionalMark ( data ) ;
146+
147+ if ( $stepTitle . length || $stepOptionalMark . length ) {
148+ const $stepLabel = $ ( '<div>' )
149+ . addClass ( STEP_LABEL_CLASS ) ;
150+
151+ $stepLabel
152+ . append ( $stepTitle )
153+ . append ( $stepOptionalMark ) ;
154+
155+ return $stepLabel ;
156+ }
157+
158+ return $ ( ) ;
159+ }
160+
161+ _prepareDefaultItemTemplate ( data : Item , $container : dxElementWrapper ) : void {
162+ const $stepIndicator = this . _getStepIndicator ( data ) ;
163+ const $stepLabel = this . _getStepLabel ( data ) ;
164+
165+ $container
166+ . append ( $stepIndicator )
167+ . append ( $stepLabel ) ;
134168 }
135169
136170 _initTemplates ( ) : void {
@@ -246,8 +280,8 @@ class Stepper extends CollectionWidgetAsync<StepperProperties> {
246280 _getConnectorValue ( ) : number {
247281 const { items = [ ] , selectedIndex = 0 } = this . option ( ) ;
248282
249- const segmentsCount = ( items . length || 1 ) - 1 ;
250- const itemRatio = 100 / ( segmentsCount || 1 ) ;
283+ const segmentsCount = items . length - 1 ;
284+ const itemRatio = 100 / Math . max ( segmentsCount , 1 ) ;
251285
252286 return selectedIndex * itemRatio ;
253287 }
0 commit comments