Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: radio/toggle buttons with clickable labels #584

Merged
merged 4 commits into from
Mar 5, 2021
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

### 2.6.2 (Unreleased)
### 2.6.2 (2021-3-5)

- [#584](https://github.com/influxdata/clockface/pull/584): Fix Clickable Labels for Toggles & RadioButtons
- [#578](https://github.com/influxdata/clockface/pull/578): Improve Lighthouse scores

### 2.6.1 (2021-2-10)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@influxdata/clockface",
"version": "2.6.1",
"version": "2.6.2",
"license": "MIT",
"main": "dist/index.js",
"style": "dist/index.css",
Expand Down
40 changes: 34 additions & 6 deletions src/Components/Inputs/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ import {
Appearance,
} from '../../Types'

/**
* To have a clickable label (clicking on the label clicks/unclicks the toggle) add a 'htmlFor'
* property to the label that matches the buttonId.
*
* for example:
*
* <Toggle
* tabIndex={2}
* value="vertical"
* id="vertical-legend-orientation"
* name="lengendOr"
* checked={legendOrientation === LEGEND_ORIENTATION_THRESHOLD_VERTICAL}
* onChange={() =>
* handleSetOrientation(LEGEND_ORIENTATION_THRESHOLD_VERTICAL)
* }
* type={InputToggleType.Radio}
* size={ComponentSize.ExtraSmall}
* color={ComponentColor.Primary}
* appearance={Appearance.Outline}
* >
* <InputLabel
* active={legendOrientation === LEGEND_ORIENTATION_THRESHOLD_VERTICAL}
* htmlFor="vertical-legend-orientation"
* >
* Vertical
* </InputLabel>
* </Toggle>
*
* and all radiobuttons in the same group should have the same name, as well.
*
*
* */
export interface ToggleProps extends Omit<StandardFunctionProps, 'id'> {
/** Unique identifier for this toggle */
id: string
Expand Down Expand Up @@ -166,15 +198,11 @@ export const Toggle = forwardRef<ToggleRef, ToggleProps>(
// (b/c of the explicit onclick handler, the 'for' linking the labels
// to the input does not toggle the button at all)
return (
<div
className={toggleClass}
style={style}
ref={containerRef}
onClick={handleClick}
>
<div className={toggleClass} style={style} ref={containerRef}>
<input
id={id}
ref={ref}
onClick={handleClick}
type={type}
name={name}
title={title}
Expand Down