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(core/toggle): link label and input field to be clickable #1587

Merged
merged 18 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"html-test-app",
"ionic-test-app",
"figma-plugin",
"documentation"
"documentation",
"storybook-docs"
]
}
5 changes: 5 additions & 0 deletions .changeset/thin-frogs-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siemens/ix': patch
---

**ix-toggle** make toggle clickable if disable property is present (Fixes #1585)
8 changes: 6 additions & 2 deletions packages/core/src/components/toggle/toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
import { a11yBoolean } from '../utils/a11y';
import { IxFormComponent } from '../utils/input';

let localId = 0;

/**
* @form-ready 2.6.0
* */
Expand Down Expand Up @@ -97,6 +99,8 @@ export class Toggle implements IxFormComponent<string> {
/** @internal */
@Event() valueChange!: EventEmitter<string>;

private readonly localId = `ix-toggle-${localId++}`;

onCheckedChange(newChecked: boolean) {
if (this.indeterminate) {
this.indeterminate = false;
Expand Down Expand Up @@ -140,9 +144,9 @@ export class Toggle implements IxFormComponent<string> {
class={{
disabled: this.disabled,
}}
onClick={() => this.onCheckedChange(!this.checked)}
>
<input
id={this.localId}
disabled={this.disabled}
indeterminate={this.indeterminate}
checked={this.checked}
Expand All @@ -154,7 +158,7 @@ export class Toggle implements IxFormComponent<string> {
this.onCheckedChange((event.target as HTMLInputElement).checked)
}
></input>
<label class="switch" tabIndex={-1}>
<label class="switch" tabIndex={-1} htmlFor={this.localId}>
<span class="slider"></span>
</label>
{!this.hideText ? (
Expand Down
1 change: 1 addition & 0 deletions packages/storybook-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@siemens/ix": "workspace:*",
"@siemens/ix-icons": "^2.2.0",
"@storybook/addon-a11y": "^8.4.2",
"@storybook/addon-actions": "^8.4.2",
"@storybook/addon-designs": "^8.0.4",
"@storybook/addon-essentials": "^8.4.2",
"@storybook/addon-interactions": "^8.4.2",
Expand Down
47 changes: 47 additions & 0 deletions packages/storybook-docs/src/stories/toggle.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* SPDX-FileCopyrightText: 2024 Siemens AG
*
* SPDX-License-Identifier: MIT
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { ArgTypes, Meta, StoryObj } from '@storybook/web-components';
import type { Components } from '@siemens/ix/components';
import { genericRender, makeArgTypes } from './utils/generic-render';
import { action } from '@storybook/addon-actions';

type Element = Components.IxToggle & {
defaultSlot: string;
['checked-change']: any;
};

const meta = {
title: 'Example/Toggle',
tags: [],
render: (args) => {
const container = genericRender('ix-toggle', args);
const ixToggle = container.querySelector(
'ix-toggle'
) as HTMLIxToggleElement;
ixToggle.addEventListener('checkedChange', action('checkedChange'));
return container;
},
argTypes: makeArgTypes<Partial<ArgTypes<Element>>>('ix-toggle'),
parameters: {
design: {
type: 'figma',
url: 'https://www.figma.com/design/r2nqdNNXXZtPmWuVjIlM1Q/iX-Components---Brand-Dark?node-id=225-5535&m=dev',
},
},
} satisfies Meta<Element>;

export default meta;
type Story = StoryObj<Element>;

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Default: Story = {
args: {
disabled: false,
},
};
33 changes: 18 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading