Skip to content

Commit

Permalink
Don't display placeholder in LinkModal.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Jan 6, 2023
1 parent 99bbad2 commit e532205
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/components/views/elements/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
} = this.props;

this.inputRef = inputRef || React.createRef();

inputProps.placeholder = inputProps.placeholder || inputProps.label;
inputProps.placeholder = inputProps.placeholder ?? inputProps.label;
inputProps.id = this.id; // this overwrites the id from props

inputProps.onFocus = this.onFocus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function LinkModal({ composer, isTextEnabled, onClose, composerContext, i
autoFocus={true}
label={_td("Text")}
value={fields.text}
placeholder=""
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFields((fields) => ({ ...fields, text: e.target.value }))
}
Expand All @@ -95,6 +96,7 @@ export function LinkModal({ composer, isTextEnabled, onClose, composerContext, i
autoFocus={!isTextEnabled}
label={_td("Link")}
value={fields.link}
placeholder=""
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFields((fields) => ({ ...fields, link: e.target.value }))
}
Expand Down
54 changes: 54 additions & 0 deletions test/components/views/elements/Field-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from "react";
import { render, screen } from "@testing-library/react";

import Field from "../../../../src/components/views/elements/Field";

describe("Field", () => {
describe("Placeholder", () => {
it("Should display a placeholder", async () => {
// When
const { rerender } = render(<Field value="" placeholder="my placeholder" />);

// Then
expect(screen.getByRole("textbox")).toHaveAttribute("placeholder", "my placeholder");

// When
rerender(<Field value="" placeholder="" />);

// Then
expect(screen.getByRole("textbox")).toHaveAttribute("placeholder", "");
});

it("Should display label as placeholder", async () => {
// When
render(<Field value="" label="my label" />);

// Then
expect(screen.getByRole("textbox")).toHaveAttribute("placeholder", "my label");
});

it("Should not display a placeholder", async () => {
// When
render(<Field value="" />);

// Then
expect(screen.getByRole("textbox")).not.toHaveAttribute("placeholder", "my placeholder");
});
});
});

0 comments on commit e532205

Please sign in to comment.