Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
{...(isDisabled && { isDisabled })}
{...(onChange && { onChange: (event, _value) => onChange(event) })}
onBlur={handleBlur}
{...(!onChange && { isReadOnly: true })}
{...(!onChange && { readOnlyVariant: "default" })}
onKeyDown={keyDownHandler}
validated={validated}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,17 @@ describe('numberInput', () => {

expect(consoleSpy).not.toHaveBeenCalled();
});

test('input is read only if onChange not passed ', () => {
render(<NumberInput inputAriaLabel="readonly input" value={5}/>);
const input = screen.getByLabelText('readonly input');
expect(input).toHaveAttribute('readOnly');
});

test('input is not read only if onChange passed ', () => {
const onChangeMock = jest.fn();
render(<NumberInput inputAriaLabel="not readonly input" value={5} onChange={onChangeMock}/>);
const input = screen.getByLabelText('not readonly input');
expect(input).not.toHaveAttribute('readOnly');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ exports[`numberInput disables lower threshold 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control"
class="pf-v5-c-form-control pf-m-readonly"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-7"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="0"
/>
Expand Down Expand Up @@ -136,14 +137,15 @@ exports[`numberInput disables upper threshold 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control"
class="pf-v5-c-form-control pf-m-readonly"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-8"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="100"
/>
Expand Down Expand Up @@ -230,14 +232,15 @@ exports[`numberInput passes button props successfully 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control"
class="pf-v5-c-form-control pf-m-readonly"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-13"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="5"
/>
Expand Down Expand Up @@ -417,14 +420,15 @@ exports[`numberInput renders custom width 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control"
class="pf-v5-c-form-control pf-m-readonly"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-11"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="5"
/>
Expand Down Expand Up @@ -510,14 +514,15 @@ exports[`numberInput renders defaults & extra props 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control"
class="pf-v5-c-form-control pf-m-readonly"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-1"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="0"
/>
Expand Down Expand Up @@ -603,7 +608,7 @@ exports[`numberInput renders disabled 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control pf-m-disabled"
class="pf-v5-c-form-control pf-m-readonly pf-m-disabled"
>
<input
aria-invalid="false"
Expand All @@ -612,6 +617,7 @@ exports[`numberInput renders disabled 1`] = `
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
disabled=""
readonly=""
type="number"
value="90"
/>
Expand Down Expand Up @@ -697,14 +703,15 @@ exports[`numberInput renders error validated 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control pf-m-error"
class="pf-v5-c-form-control pf-m-readonly pf-m-error"
>
<input
aria-invalid="true"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-3"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="0"
/>
Expand Down Expand Up @@ -810,14 +817,15 @@ exports[`numberInput renders success validated 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control pf-m-success"
class="pf-v5-c-form-control pf-m-readonly pf-m-success"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-2"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="0"
/>
Expand Down Expand Up @@ -928,14 +936,15 @@ exports[`numberInput renders unit & position 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control"
class="pf-v5-c-form-control pf-m-readonly"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-10"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="5"
/>
Expand Down Expand Up @@ -1020,14 +1029,15 @@ exports[`numberInput renders unit 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control"
class="pf-v5-c-form-control pf-m-readonly"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-9"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="5"
/>
Expand Down Expand Up @@ -1117,14 +1127,15 @@ exports[`numberInput renders value 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control"
class="pf-v5-c-form-control pf-m-readonly"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-5"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="90"
/>
Expand Down Expand Up @@ -1209,14 +1220,15 @@ exports[`numberInput renders warning validated 1`] = `
class="pf-v5-c-input-group__item"
>
<div
class="pf-v5-c-form-control pf-m-warning"
class="pf-v5-c-form-control pf-m-readonly pf-m-warning"
>
<input
aria-invalid="false"
aria-label="Input"
data-ouia-component-id="OUIA-Generated-TextInputBase-4"
data-ouia-component-type="PF5/TextInput"
data-ouia-safe="true"
readonly=""
type="number"
value="0"
/>
Expand Down