Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SegmentedControl): option label defaults to value #7052

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ function SegmentedControlOption({ isSelected, label, onClick, value, ...buttonPr
[onClick, value],
);

return <Button {...buttonProps} onClick={handleClick} minimal={!isSelected} text={label} />;
return <Button {...buttonProps} onClick={handleClick} minimal={!isSelected} text={label ?? value} />;
}
SegmentedControlOption.displayName = `${DISPLAYNAME_PREFIX}.SegmentedControlOption`;
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe("<SegmentedControl>", () => {
assert.isTrue(wrapper.find(`.${testClassName}`).hostNodes().exists());
});

it("button text defaults to value when no label is passed", () => {
mountSegmentedControl({ options: [{ value: "val" }] });
const optionButtons = containerElement.querySelectorAll("button")!;
assert.equal(optionButtons[0].textContent, "val");
});

it("when no default value passed, first button gets tabIndex=0, none have aria-checked initially", () => {
const wrapper = mountSegmentedControl();
assert.lengthOf(wrapper.find("[tabIndex=0]").hostNodes(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const BooleanOrUndefinedSelect: React.FC<BooleanOrUndefinedSelectProps> =
<SegmentedControl
fill={true}
options={[
{ disabled, label: "undefined", value: "undefined" },
{ disabled, label: "true", value: "true" },
{ disabled, label: "false", value: "false" },
{ disabled, value: "undefined" },
{ disabled, value: "true" },
{ disabled, value: "false" },
]}
onValueChange={handleChange}
small={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ export class DrawerExample extends React.PureComponent<ExampleProps<BlueprintExa
<SegmentedControl
fill={true}
options={[
{ label: Position.TOP, value: Position.TOP },
{ label: Position.RIGHT, value: Position.RIGHT },
{ label: Position.BOTTOM, value: Position.BOTTOM },
{ label: Position.LEFT, value: Position.LEFT },
{ value: Position.TOP },
{ value: Position.RIGHT },
{ value: Position.BOTTOM },
{ value: Position.LEFT },
]}
onValueChange={this.handlePositionChange}
small={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ export function MenuItemExample(props: ExampleProps) {
<IntentSelect intent={intent} onChange={setIntent} showClearButton={true} />
<FormGroup label="Role structure">
<SegmentedControl
options={[
{ label: "menuitem", value: "menuitem" },
{ label: "listoption", value: "listoption" },
]}
options={[{ value: "menuitem" }, { value: "listoption" }]}
onValueChange={handleRoleStructureChange}
small={true}
value={roleStructure}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class MultistepDialogExample extends React.PureComponent<
<SegmentedControl
fill={true}
onValueChange={this.handleNavPositionChange}
options={NAV_POSITIONS.map(p => ({ label: p, value: p }))}
options={NAV_POSITIONS.map(p => ({ value: p }))}
small={true}
value={navPosition}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,8 @@ export const SegmentedControlExample: React.FC<ExampleProps> = props => {
defaultValue="none"
inline={true}
options={[
{
label: "None",
value: "none",
},
{
label: "Primary",
value: "primary",
},
{ label: "None", value: "none" },
{ label: "Primary", value: "primary" },
]}
onValueChange={handleIntentChange}
small={true}
Expand All @@ -65,23 +59,10 @@ export const SegmentedControlExample: React.FC<ExampleProps> = props => {
inline={inline}
intent={intent}
options={[
{
label: "List",
value: "list",
},
{
label: "Grid",
value: "grid",
},
{
disabled: true,
label: "Disabled",
value: "disabled",
},
{
label: "Gallery",
value: "gallery",
},
{ label: "List", value: "list" },
{ label: "Grid", value: "grid" },
{ disabled: true, label: "Disabled", value: "disabled" },
{ label: "Gallery", value: "gallery" },
]}
large={size === "large"}
small={size === "small"}
Expand Down