• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eclipsesource / jsonforms / 8687813307

15 Apr 2024 10:48AM UTC coverage: 84.383% (-0.007%) from 84.39%
8687813307

push

github

web-flow
react-material: Remove usage of Material's Hidden component (#2315)

Removes the deprecated <Hidden> component and instead returns null if the hidden property is set.

Closes #2107

10062 of 22976 branches covered (43.79%)

52 of 60 new or added lines in 21 files covered. (86.67%)

1 existing line in 1 file now uncovered.

17512 of 20753 relevant lines covered (84.38%)

27.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.35
/packages/material-renderers/src/controls/MaterialBooleanToggleControl.tsx
1
/*
2
  The MIT License
3

4
  Copyright (c) 2017-2021 EclipseSource Munich
5
  https://github.com/eclipsesource/jsonforms
6

7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
  of this software and associated documentation files (the "Software"), to deal
9
  in the Software without restriction, including without limitation the rights
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  copies of the Software, and to permit persons to whom the Software is
12
  furnished to do so, subject to the following conditions:
13

14
  The above copyright notice and this permission notice shall be included in
15
  all copies or substantial portions of the Software.
16

17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
  THE SOFTWARE.
24
*/
25
import isEmpty from 'lodash/isEmpty';
31✔
26
import merge from 'lodash/merge';
31✔
27
import React from 'react';
31✔
28
import {
31✔
29
  isBooleanControl,
30
  RankedTester,
31
  rankWith,
32
  ControlProps,
33
  optionIs,
34
  and,
35
  isDescriptionHidden,
36
} from '@jsonforms/core';
37
import { withJsonFormsControlProps } from '@jsonforms/react';
31✔
38
import { FormControlLabel, FormHelperText, Tooltip } from '@mui/material';
31✔
39
import { MuiToggle } from '../mui-controls/MuiToggle';
31✔
40

41
export const MaterialBooleanToggleControl = ({
31✔
42
  data,
20✔
43
  visible,
20✔
44
  label,
20✔
45
  id,
20✔
46
  enabled,
20✔
47
  uischema,
20✔
48
  schema,
20✔
49
  rootSchema,
20✔
50
  handleChange,
20✔
51
  errors,
20✔
52
  path,
20✔
53
  config,
20✔
54
  description,
20✔
55
}: ControlProps) => {
56
  const isValid = errors.length === 0;
20✔
57
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
20✔
58

59
  const showDescription = !isDescriptionHidden(
20✔
60
    visible,
61
    description,
62
    // Checkboxes do not receive focus until they are used, so
63
    // we cannot rely on focus as criteria for showing descriptions.
64
    // So we pass "false" to treat it as unfocused.
65
    false,
66
    appliedUiSchemaOptions.showUnfocusedDescription
67
  );
68

69
  const showTooltip =
70
    !showDescription &&
20✔
71
    !isDescriptionHidden(
72
      visible,
73
      description,
74
      // Tooltips have their own focus handlers, so we do not need to rely
75
      // on focus state here. So we pass 'true' to treat it as focused.
76
      true,
77
      // We also pass true here for showUnfocusedDescription since it should
78
      // render regardless of that setting.
79
      true
80
    );
81

82
  const firstFormHelperText = showDescription
20✔
83
    ? description
84
    : !isValid
19✔
85
    ? errors
86
    : null;
87
  const secondFormHelperText = showDescription && !isValid ? errors : null;
20!
88

89
  const descriptionIds = [];
20✔
90
  const tooltipId = `${id}-tip`;
20✔
91
  const helpId1 = `${id}-help1`;
20✔
92
  const helpId2 = `${id}-help2`;
20✔
93
  if (showTooltip) {
20✔
94
    descriptionIds.push(tooltipId);
19✔
95
  }
96
  if (firstFormHelperText) {
20✔
97
    descriptionIds.push(helpId1);
2✔
98
  }
99
  if (secondFormHelperText) {
20!
100
    descriptionIds.push(helpId2);
×
101
  }
102
  const ariaDescribedBy = descriptionIds.join(' ');
20✔
103

104
  if (!visible) {
20!
NEW
105
    return null;
×
106
  }
107

108
  return (
20✔
109
    <>
110
      <Tooltip id={tooltipId} title={showTooltip ? description : ''}>
20✔
111
        <FormControlLabel
112
          label={label}
113
          id={id}
114
          control={
115
            <MuiToggle
116
              id={`${id}-input`}
117
              isValid={isEmpty(errors)}
118
              data={data}
119
              enabled={enabled}
120
              visible={visible}
121
              path={path}
122
              uischema={uischema}
123
              schema={schema}
124
              rootSchema={rootSchema}
125
              handleChange={handleChange}
126
              errors={errors}
127
              config={config}
128
              inputProps={{
129
                'aria-describedby': ariaDescribedBy,
130
              }}
131
            />
132
          }
133
        />
134
      </Tooltip>
135
      <FormHelperText id={helpId1} error={!isValid && !showDescription}>
21✔
136
        {firstFormHelperText}
137
      </FormHelperText>
138
      <FormHelperText id={helpId2} error={!isValid}>
139
        {secondFormHelperText}
140
      </FormHelperText>
141
    </>
142
  );
143
};
144

145
export const materialBooleanToggleControlTester: RankedTester = rankWith(
31✔
146
  3,
147
  and(isBooleanControl, optionIs('toggle', true))
148
);
149

150
export default withJsonFormsControlProps(MaterialBooleanToggleControl);
31✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc