@fluid-topics/ft-chip-choice 2.0.16 → 2.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import { PropertyValues } from "lit";
2
1
  import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
3
2
  import { FtChipChoiceOptionProperties } from "./ft-chip-choice-option.properties";
4
3
  import { FtChip } from "@fluid-topics/ft-chip";
@@ -20,7 +19,5 @@ export declare class FtChipChoiceOption extends FtLitElement implements FtChipCh
20
19
  chip: FtChip;
21
20
  static styles: import("lit").CSSResult;
22
21
  protected render(): import("lit-html").TemplateResult<1>;
23
- private onKeyDown;
24
- protected update(changedProperties: PropertyValues): void;
25
- private onChange;
22
+ private onInputChange;
26
23
  }
@@ -5,10 +5,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { html } from "lit";
8
- import { property, query } from "lit/decorators.js";
9
- import { FtLitElement } from "@fluid-topics/ft-wc-utils";
8
+ import { property, query, } from "lit/decorators.js";
9
+ import { FtLitElement, } from "@fluid-topics/ft-wc-utils";
10
10
  import { optionStyles } from "./ft-chip-choice-option.styles";
11
11
  import { FtChip } from "@fluid-topics/ft-chip";
12
+ import { FtIcons } from "ft-icon/build";
12
13
  export class FtChipChoiceOptionChangeEvent extends CustomEvent {
13
14
  constructor(value, selected) {
14
15
  super("ft-chip-choice-option-change", { detail: { value: value, selected: selected }, bubbles: true, composed: true });
@@ -27,39 +28,33 @@ export class FtChipChoiceOption extends FtLitElement {
27
28
  }
28
29
  render() {
29
30
  return html `
30
- <ft-chip clickable
31
- part="chip"
32
- icon=${this.selected ? "CHECK" : ""}
33
- label=${this.label}
34
- ?dense=${this.dense}
35
- ?highlighted=${this.selected}
36
- ?multiLine=${this.multiLine}
37
- @click=${this.onChange}
38
- @keydown=${this.onKeyDown}>
39
- <slot></slot>
40
- </ft-chip>
31
+ <label>
32
+ <input
33
+ type="${this.role === "radio" ? "radio" : "checkbox"}"
34
+ name="${this.name}"
35
+ value="${this.value}"
36
+ .checked=${this.selected}
37
+ aria-label="${this.label}"
38
+ @change=${this.onInputChange}
39
+ />
40
+ <ft-chip
41
+ icon="${this.selected ? FtIcons.CHECK : ""}"
42
+ label="${this.label}"
43
+ ?dense=${this.dense}
44
+ ?highlighted=${this.selected}
45
+ ?multiLine=${this.multiLine}>
46
+ <slot></slot>
47
+ </ft-chip>
48
+ </label>
41
49
  `;
42
50
  }
43
- onKeyDown(e) {
44
- // Prevent the page from scrolling on space by default
45
- if (e.key == " ") {
46
- e.preventDefault();
47
- }
48
- }
49
- update(changedProperties) {
50
- super.update(changedProperties);
51
- if (changedProperties.has("selected")) {
52
- this.ariaChecked = this.selected ? "true" : "false";
53
- }
54
- }
55
- onChange(event) {
56
- event.preventDefault();
57
- this.selected = !this.selected;
51
+ onInputChange(event) {
52
+ this.selected = event.target.checked;
58
53
  this.dispatchEvent(new FtChipChoiceOptionChangeEvent(this.value, this.selected));
59
54
  }
60
55
  }
61
56
  FtChipChoiceOption.elementDefinitions = {
62
- "ft-chip": FtChip
57
+ "ft-chip": FtChip,
63
58
  };
64
59
  FtChipChoiceOption.styles = optionStyles;
65
60
  __decorate([
@@ -81,7 +76,7 @@ __decorate([
81
76
  property({ type: Boolean })
82
77
  ], FtChipChoiceOption.prototype, "multiLine", void 0);
83
78
  __decorate([
84
- property({ reflect: true, attribute: "role" })
79
+ property()
85
80
  ], FtChipChoiceOption.prototype, "role", void 0);
86
81
  __decorate([
87
82
  query("ft-chip")
@@ -1,6 +1,6 @@
1
1
  import { css } from "lit";
2
- import { designSystemVariables, FtCssVariableFactory, setVariable } from "@fluid-topics/ft-wc-utils";
3
- import { FtChipCssVariables, FtChipHighlightedCssVariables } from "@fluid-topics/ft-chip/build/ft-chip.styles";
2
+ import { designSystemVariables, FtCssVariableFactory, setVariable, } from "@fluid-topics/ft-wc-utils";
3
+ import { FtChipCssVariables, FtChipHighlightedCssVariables, } from "@fluid-topics/ft-chip/build/ft-chip.styles";
4
4
  export const FtChipChoiceOptionCssVariables = {
5
5
  color: FtCssVariableFactory.create("--ft-chip-choice-option--color", "", "COLOR", designSystemVariables.colorOnSurface),
6
6
  borderColor: FtCssVariableFactory.create("--ft-chip-choice-option--border-color", "", "COLOR", designSystemVariables.colorOutline),
@@ -10,7 +10,26 @@ export const FtChipChoiceOptionCssVariables = {
10
10
  };
11
11
  // language=CSS
12
12
  export const optionStyles = css `
13
- [part="chip"] {
13
+ label {
14
+ display: contents;
15
+ }
16
+
17
+ input {
18
+ clip: rect(0 0 0 0);
19
+ clip-path: inset(50%);
20
+ height: 1px;
21
+ overflow: hidden;
22
+ position: absolute;
23
+ white-space: nowrap;
24
+ width: 1px;
25
+ }
26
+
27
+ input:focus + ft-chip::part(chip) {
28
+ outline: 2px solid ${designSystemVariables.colorPrimary};
29
+ outline-offset: 2px;
30
+ }
31
+
32
+ ft-chip::part(chip) {
14
33
  ${setVariable(FtChipCssVariables.color, FtChipChoiceOptionCssVariables.color)};
15
34
  ${setVariable(FtChipCssVariables.borderColor, FtChipChoiceOptionCssVariables.borderColor)};
16
35
  ${setVariable(FtChipCssVariables.backgroundColor, FtChipChoiceOptionCssVariables.backgroundColor)};