Skip to content

Commit

Permalink
[Slider][a11y] Limit values to 2 decimals in the content description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 676427467
  • Loading branch information
paulfthomas authored and dsn5ft committed Sep 20, 2024
1 parent d049a42 commit cebb057
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/java/com/google/android/material/slider/BaseSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -3264,7 +3265,13 @@ protected void onPopulateNodeForVirtualView(
}
}

info.setRangeInfo(RangeInfoCompat.obtain(RANGE_TYPE_FLOAT, valueFrom, valueTo, value));
DecimalFormat df = new DecimalFormat("#.##");
info.setRangeInfo(
RangeInfoCompat.obtain(
RANGE_TYPE_FLOAT,
Float.parseFloat(df.format(valueFrom)),
Float.parseFloat(df.format(valueTo)),
Float.parseFloat(df.format(value))));
info.setClassName(SeekBar.class.getName());
StringBuilder contentDescription = new StringBuilder();
// Add the content description of the slider.
Expand Down

0 comments on commit cebb057

Please sign in to comment.