@fluid-topics/ft-switch 1.1.107 → 1.1.111

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.
@@ -22,10 +22,14 @@ export declare class FtSwitchOption extends FtLitElement implements FtSwitchOpti
22
22
  unselectable: boolean;
23
23
  private slottedContent?;
24
24
  private input;
25
+ isFocused: boolean;
25
26
  focus(): void;
26
27
  protected update(props: PropertyValues<any>): void;
27
28
  protected render(): HTMLTemplateResult;
28
29
  private addTooltip;
30
+ connectedCallback(): void;
31
+ disconnectedCallback(): void;
32
+ private onFocusout;
29
33
  private onChange;
30
34
  private getLabel;
31
35
  private resolveIcon;
@@ -5,7 +5,7 @@ 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, nothing } from "lit";
8
- import { property, query } from "lit/decorators.js";
8
+ import { property, query, state } from "lit/decorators.js";
9
9
  import { FtLitElement, isSafari, safariEllipsisFix } from "@fluid-topics/ft-wc-utils";
10
10
  import { FtRipple } from "@fluid-topics/ft-ripple";
11
11
  import { FtTypography } from "@fluid-topics/ft-typography";
@@ -32,6 +32,7 @@ class FtSwitchOption extends FtLitElement {
32
32
  this.selected = false;
33
33
  this.trailingIcon = false;
34
34
  this.unselectable = false;
35
+ this.isFocused = false;
35
36
  }
36
37
  focus() {
37
38
  this.input.focus();
@@ -47,6 +48,7 @@ class FtSwitchOption extends FtLitElement {
47
48
  "ft-switch-option": true,
48
49
  "ft-switch-option--trailing-icon": this.trailingIcon,
49
50
  "ft-switch-option--selected": this.selected,
51
+ "ft-switch-option--focused": this.isFocused,
50
52
  };
51
53
  return this.addTooltip(html `
52
54
  <label part="label" for="input" class=${classMap(classes)}
@@ -75,6 +77,17 @@ class FtSwitchOption extends FtLitElement {
75
77
  </ft-tooltip>
76
78
  `;
77
79
  }
80
+ connectedCallback() {
81
+ super.connectedCallback();
82
+ this.addEventListener("focusout", this.onFocusout);
83
+ }
84
+ disconnectedCallback() {
85
+ super.disconnectedCallback();
86
+ this.removeEventListener("focusout", this.onFocusout);
87
+ }
88
+ onFocusout(e) {
89
+ this.isFocused = false;
90
+ }
78
91
  onChange() {
79
92
  this.selected = this.unselectable ? !this.selected : true;
80
93
  this.dispatchEvent(new SwitchOptionChangeByUser(this.selected));
@@ -138,4 +151,7 @@ __decorate([
138
151
  __decorate([
139
152
  query(".ft-switch-option--input")
140
153
  ], FtSwitchOption.prototype, "input", void 0);
154
+ __decorate([
155
+ state()
156
+ ], FtSwitchOption.prototype, "isFocused", void 0);
141
157
  export { FtSwitchOption };
@@ -72,6 +72,10 @@ export const optionStyles = css `
72
72
  color: ${FtSwitchCssVariables.selectedTextColor};
73
73
  }
74
74
 
75
+ .ft-switch-option--focused {
76
+ outline: 1px solid ${FtSwitchCssVariables.outlineColor};
77
+ }
78
+
75
79
  .ft-switch-option--label[hidden] {
76
80
  display: none;
77
81
  }
@@ -10,8 +10,10 @@ export declare class FtSwitch extends FtLitElement implements FtSwitchProperties
10
10
  get value(): any;
11
11
  dense: boolean;
12
12
  unselectable: boolean;
13
+ label?: string;
13
14
  private slottedContent?;
14
15
  private selectedOption?;
16
+ private displayFocusWhenUsingKeyboard;
15
17
  private options;
16
18
  private ftSwitchDiv;
17
19
  protected update(props: PropertyValues<any>): void;
@@ -21,6 +21,7 @@ class FtSwitch extends FtLitElement {
21
21
  super(...arguments);
22
22
  this.dense = false;
23
23
  this.unselectable = false;
24
+ this.displayFocusWhenUsingKeyboard = false;
24
25
  this.options = [];
25
26
  }
26
27
  get value() {
@@ -42,7 +43,7 @@ class FtSwitch extends FtLitElement {
42
43
  "ft-switch--dense": this.dense,
43
44
  };
44
45
  return html `
45
- <div @keydown=${this.onKeyDown} tabindex="0" class="${classMap(classes)}">
46
+ <div @keydown=${this.onKeyDown} tabindex="-1" class="${classMap(classes)}" role="radiogroup" aria-label=${this.label}>
46
47
  <slot @slotchange=${this.onSlotchange}
47
48
  @option-change=${this.onOptionChangeByScript}
48
49
  @option-change-by-user=${this.onOptionChangeByUser}
@@ -58,8 +59,13 @@ class FtSwitch extends FtLitElement {
58
59
  if (e.key == "ArrowUp" || e.key == "ArrowLeft") {
59
60
  newIndex = this.selectedOption ? this.options.indexOf(this.selectedOption) - 1 : this.options.length - 1;
60
61
  }
62
+ if (e.code == "Space") {
63
+ newIndex = this.options.indexOf(e.target);
64
+ }
61
65
  if (newIndex != undefined) {
62
66
  e.preventDefault();
67
+ this.options[this.fixIndex(newIndex)].focus();
68
+ this.displayFocusWhenUsingKeyboard = true;
63
69
  this.options[this.fixIndex(newIndex)].selected = true;
64
70
  }
65
71
  }
@@ -83,7 +89,11 @@ class FtSwitch extends FtLitElement {
83
89
  this.selectedOption = this.options.find(option => option.selected);
84
90
  }
85
91
  registerOption(option) {
86
- option.setAttribute("tabindex", "-1");
92
+ var _a;
93
+ (_a = option.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll("input").forEach(input => {
94
+ input.setAttribute("tabindex", "-1");
95
+ });
96
+ option.setAttribute("tabindex", "0");
87
97
  option.unselectable = this.unselectable;
88
98
  this.options.push(option);
89
99
  }
@@ -95,6 +105,7 @@ class FtSwitch extends FtLitElement {
95
105
  onOptionChangeByUser(e) {
96
106
  var _a;
97
107
  e.stopPropagation();
108
+ this.displayFocusWhenUsingKeyboard = false;
98
109
  this.onOptionChange(e.target);
99
110
  this.dispatchEvent(new FtSwitchChange((_a = this.selectedOption) === null || _a === void 0 ? void 0 : _a.value));
100
111
  }
@@ -120,6 +131,9 @@ class FtSwitch extends FtLitElement {
120
131
  updateOptions() {
121
132
  this.options.forEach(option => {
122
133
  option.selected = option === this.selectedOption;
134
+ if (this.displayFocusWhenUsingKeyboard) {
135
+ option.isFocused = option === this.selectedOption;
136
+ }
123
137
  });
124
138
  }
125
139
  }
@@ -166,12 +180,18 @@ __decorate([
166
180
  __decorate([
167
181
  property({ type: Boolean })
168
182
  ], FtSwitch.prototype, "unselectable", void 0);
183
+ __decorate([
184
+ property()
185
+ ], FtSwitch.prototype, "label", void 0);
169
186
  __decorate([
170
187
  query(".ft-switch slot")
171
188
  ], FtSwitch.prototype, "slottedContent", void 0);
172
189
  __decorate([
173
190
  state()
174
191
  ], FtSwitch.prototype, "selectedOption", void 0);
192
+ __decorate([
193
+ state()
194
+ ], FtSwitch.prototype, "displayFocusWhenUsingKeyboard", void 0);
175
195
  __decorate([
176
196
  query(".ft-switch")
177
197
  ], FtSwitch.prototype, "ftSwitchDiv", void 0);