Skip to content

Commit

Permalink
Fix visibility of placeholder on show for Entry
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jul 18, 2020
1 parent 20b16cf commit f41b9b5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
9 changes: 7 additions & 2 deletions widget/entry.go
Expand Up @@ -98,7 +98,12 @@ func (e *Entry) CreateRenderer() fyne.WidgetRenderer {

e.propertyLock.Lock()
defer e.propertyLock.Unlock()
objects := []fyne.CanvasObject{line, e.placeholderProvider(), e.textProvider(), cursor}
provider := e.textProvider()
placeholder := e.placeholderProvider()
if provider.len() != 0 {
placeholder.Hide()
}
objects := []fyne.CanvasObject{line, placeholder, provider, cursor}

if e.Password && e.ActionItem == nil {
// An entry widget has been created via struct setting manually
Expand Down Expand Up @@ -1038,7 +1043,7 @@ func (r *entryRenderer) Refresh() {
return
}

if provider.len() == 0 && r.entry.Visible() {
if provider.len() == 0 {
placeholder.Show()
} else if placeholder.Visible() {
placeholder.Hide()
Expand Down
17 changes: 17 additions & 0 deletions widget/entry_test.go
Expand Up @@ -880,6 +880,23 @@ func TestEntry_PasteOverSelection(t *testing.T) {
assert.Equal(t, "TeInsertng", e.Text)
}

func TestEntry_Placeholder(t *testing.T) {
entry := &widget.Entry{}
entry.Text = "Text"
entry.PlaceHolder = "Placehold"

window := test.NewWindow(entry)
defer teardownImageTest(window)
c := window.Canvas()

assert.Equal(t, "Text", entry.Text)
test.AssertImageMatches(t, "entry/placeholder_withtext.png", c.Capture())

entry.SetText("")
assert.Equal(t, "", entry.Text)
test.AssertImageMatches(t, "entry/placeholder_initial.png", c.Capture())
}

func TestPasswordEntry_Placeholder(t *testing.T) {
entry, window := setupPasswordImageTest()
defer teardownImageTest(window)
Expand Down
Binary file added widget/testdata/entry/placeholder_initial.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added widget/testdata/entry/placeholder_withtext.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f41b9b5

Please sign in to comment.