File tree Expand file tree Collapse file tree
src/main/java/com/flowingcode/vaadin/addons/togglebutton Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -218,8 +218,7 @@ public ToggleButton setRightLabel(String label) {
218218 * @since 1.0.0
219219 */
220220 public ToggleButton setLeftIcon (Component icon ) {
221- icon .getElement ().setAttribute ("slot" , "left" );
222- add (icon );
221+ setSlottedIcon (icon , "left" );
223222 return this ;
224223 }
225224
@@ -231,8 +230,15 @@ public ToggleButton setLeftIcon(Component icon) {
231230 * @since 1.0.0
232231 */
233232 public ToggleButton setRightIcon (Component icon ) {
234- icon .getElement ().setAttribute ("slot" , "right" );
235- add (icon );
233+ setSlottedIcon (icon , "right" );
236234 return this ;
237235 }
236+
237+ private void setSlottedIcon (Component icon , String slot ) {
238+ getElement ().getChildren ()
239+ .filter (e -> slot .equals (e .getAttribute ("slot" )))
240+ .forEach (e -> e .removeFromParent ());
241+ icon .getElement ().setAttribute ("slot" , slot );
242+ add (icon );
243+ }
238244}
You can’t perform that action at this time.
0 commit comments