vira 31.1.2 → 31.2.0

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.
@@ -23,6 +23,18 @@ export declare const ViraMenuTrigger: import("element-vir").DeclarativeElementDe
23
23
  popUpOffset: PopUpOffset;
24
24
  keepOpenAfterInteraction: boolean;
25
25
  menuCornerStyle: ViraMenuCornerStyle;
26
+ /**
27
+ * If true, the focus outline is moved inside the element.
28
+ *
29
+ * @default false
30
+ */
31
+ useInsideFocus: boolean;
32
+ /**
33
+ * When `true`, the trigger will focus itself when the pop-up closes.
34
+ *
35
+ * @default false
36
+ */
37
+ focusOnClose: boolean;
26
38
  } & PopUpTriggerPosition>, {
27
39
  navController: undefined | NavController;
28
40
  popUpManager: undefined | PopUpManager;
@@ -87,6 +87,10 @@ export declare const ViraPopUpTrigger: import("element-vir").DeclarativeElementD
87
87
  keepOpenAfterInteraction: boolean;
88
88
  /** All values in px. */
89
89
  popUpOffset: PopUpOffset;
90
+ /** If true, the focus outline is moved inside the element. */
91
+ useInsideFocus: boolean;
92
+ /** When `true`, the trigger will focus itself when the pop-up closes. */
93
+ focusOnClose: boolean;
90
94
  }>, {
91
95
  /** `undefined` means the pop up is not currently showing. */
92
96
  showPopUpResult: ShowPopUpResult | undefined;
@@ -102,4 +106,4 @@ export declare const ViraPopUpTrigger: import("element-vir").DeclarativeElementD
102
106
  navController: NavController;
103
107
  popUpManager: PopUpManager;
104
108
  }>;
105
- }, "vira-pop-up-trigger-disabled", "vira-pop-up-trigger-", readonly ["trigger", "popUp"], readonly []>;
109
+ }, "vira-pop-up-trigger-disabled" | "vira-pop-up-trigger-inside-focus" | "vira-pop-up-trigger-outside-focus", "vira-pop-up-trigger-", readonly ["trigger", "popUp"], readonly []>;
@@ -58,6 +58,8 @@ export const ViraPopUpTrigger = defineViraElement()({
58
58
  ],
59
59
  hostClasses: {
60
60
  'vira-pop-up-trigger-disabled': ({ inputs }) => !!inputs.isDisabled,
61
+ 'vira-pop-up-trigger-inside-focus': ({ inputs }) => !!inputs.useInsideFocus,
62
+ 'vira-pop-up-trigger-outside-focus': ({ inputs }) => !inputs.useInsideFocus,
61
63
  },
62
64
  styles: ({ hostClasses }) => css `
63
65
  :host {
@@ -75,11 +77,16 @@ export const ViraPopUpTrigger = defineViraElement()({
75
77
  position: relative;
76
78
  flex-grow: 1;
77
79
  box-sizing: border-box;
80
+ }
78
81
 
82
+ ${hostClasses['vira-pop-up-trigger-inside-focus'].selector} .dropdown-wrapper {
79
83
  ${createFocusStyles({
80
- elementBorderSize: '1px',
84
+ renderInside: true,
81
85
  })}
82
86
  }
87
+ ${hostClasses['vira-pop-up-trigger-outside-focus'].selector} .dropdown-wrapper {
88
+ ${createFocusStyles()}
89
+ }
83
90
 
84
91
  .dropdown-trigger {
85
92
  box-sizing: border-box;
@@ -142,7 +149,7 @@ export const ViraPopUpTrigger = defineViraElement()({
142
149
  showPopUpResult: undefined,
143
150
  });
144
151
  dispatch(new events.openChange(undefined));
145
- if (!inputs.isDisabled) {
152
+ if (inputs.focusOnClose && !inputs.isDisabled) {
146
153
  const dropdownWrapper = host.shadowRoot.querySelector('.dropdown-wrapper');
147
154
  assert.instanceOf(dropdownWrapper, HTMLButtonElement, 'failed to find dropdown wrapper child');
148
155
  dropdownWrapper.focus();
@@ -150,6 +150,7 @@ export const ViraDropdown = defineViraElement()({
150
150
  return html `
151
151
  <${ViraPopUpTrigger.assign({
152
152
  ...inputs,
153
+ focusOnClose: true,
153
154
  popUpOffset: {
154
155
  vertical: -1,
155
156
  right: 24,
@@ -9,17 +9,18 @@ import { type SingleCssVarDefinition } from 'lit-css-vars';
9
9
  *
10
10
  * @category Styles
11
11
  */
12
- export declare function createFocusStyles({ elementBorderSize, outlineGap, outlineWidth, noNesting, outlineColor, borderRadius, }: {
12
+ export declare function createFocusStyles({ elementBorderSize, outlineGap, outlineWidth, noNesting, outlineColor, borderRadius, renderInside, }?: PartialWithUndefined<{
13
13
  /**
14
14
  * ElementBorderSize here is used to fix the outline when the element these styles are attached
15
15
  * to has a border. The dev must specify that border size here for the offsets to be calculated
16
16
  * correctly.
17
17
  */
18
18
  elementBorderSize: SingleCssVarDefinition | string;
19
- } & PartialWithUndefined<{
20
19
  outlineGap: SingleCssVarDefinition | string;
21
20
  outlineWidth: SingleCssVarDefinition | string;
22
21
  borderRadius: SingleCssVarDefinition | string;
23
22
  outlineColor: SingleCssVarDefinition | string;
24
23
  noNesting: boolean;
24
+ /** Render the focus outline inside the element instead of outside. */
25
+ renderInside: boolean;
25
26
  }>): CSSResult;
@@ -17,21 +17,36 @@ function cssValueOrRaw(value) {
17
17
  *
18
18
  * @category Styles
19
19
  */
20
- export function createFocusStyles({ elementBorderSize, outlineGap = '2px', outlineWidth = '2px', noNesting, outlineColor = viraFormCssVars['vira-form-focus-outline-color'], borderRadius = viraFormCssVars['vira-form-focus-outline-border-radius'], }) {
21
- const outlineSpacing = css `calc(${cssValueOrRaw(outlineWidth)} + ${cssValueOrRaw(outlineGap)} + ${cssValueOrRaw(elementBorderSize)})`;
22
- const styles = css `
23
- content: '';
24
- top: calc(${outlineSpacing} * -1);
25
- left: calc(${outlineSpacing} * -1);
26
- position: absolute;
27
- width: calc(100% + calc(${outlineSpacing} * 2));
28
- height: calc(100% + calc(${outlineSpacing} * 2));
29
- box-sizing: border-box;
30
- pointer-events: none;
31
- border: ${cssValueOrRaw(outlineWidth)} solid ${cssValueOrRaw(outlineColor)};
32
- border-radius: ${cssValueOrRaw(borderRadius)};
33
- z-index: 100;
34
- `;
20
+ export function createFocusStyles({ elementBorderSize = '1px', outlineGap = '2px', outlineWidth = '2px', noNesting, outlineColor = viraFormCssVars['vira-form-focus-outline-color'], borderRadius = viraFormCssVars['vira-form-focus-outline-border-radius'], renderInside, } = {}) {
21
+ const insetSpacing = css `calc(${cssValueOrRaw(outlineGap)})`;
22
+ const outsetSpacing = css `calc(${cssValueOrRaw(outlineWidth)} + ${cssValueOrRaw(outlineGap)} + ${cssValueOrRaw(elementBorderSize)})`;
23
+ const styles = renderInside
24
+ ? css `
25
+ content: '';
26
+ top: ${insetSpacing};
27
+ left: ${insetSpacing};
28
+ position: absolute;
29
+ width: calc(100% - calc(${insetSpacing} * 2));
30
+ height: calc(100% - calc(${insetSpacing} * 2));
31
+ box-sizing: border-box;
32
+ pointer-events: none;
33
+ border: ${cssValueOrRaw(outlineWidth)} solid ${cssValueOrRaw(outlineColor)};
34
+ border-radius: ${cssValueOrRaw(borderRadius)};
35
+ z-index: 100;
36
+ `
37
+ : css `
38
+ content: '';
39
+ top: calc(${outsetSpacing} * -1);
40
+ left: calc(${outsetSpacing} * -1);
41
+ position: absolute;
42
+ width: calc(100% + calc(${outsetSpacing} * 2));
43
+ height: calc(100% + calc(${outsetSpacing} * 2));
44
+ box-sizing: border-box;
45
+ pointer-events: none;
46
+ border: ${cssValueOrRaw(outlineWidth)} solid ${cssValueOrRaw(outlineColor)};
47
+ border-radius: ${cssValueOrRaw(borderRadius)};
48
+ z-index: 100;
49
+ `;
35
50
  if (noNesting) {
36
51
  return styles;
37
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vira",
3
- "version": "31.1.2",
3
+ "version": "31.2.0",
4
4
  "description": "A simple and highly versatile design system using element-vir.",
5
5
  "keywords": [
6
6
  "design",