Skip to content

Commit

Permalink
Fixed issue with -ArgumentList and buttons. (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Apr 15, 2020
1 parent 4789f69 commit 20b874e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/UniversalDashboard.MaterialUI/Components/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const UdButton = props => {

const handleClick = () => {
if (props.onClick == null) return
props.notifyOfEvent('onClick', '')
props.onClick();
}

var icon = props.icon ? (
Expand Down
12 changes: 4 additions & 8 deletions src/UniversalDashboard.MaterialUI/Scripts/button.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function New-UDButton {
[switch]$FullWidth,

[Parameter (Position = 7)]
[object]$OnClick,
[Endpoint]$OnClick,

[Parameter (Position = 8)]
[ValidateSet("small", "medium", "large")]
Expand All @@ -83,13 +83,9 @@ function New-UDButton {

End {

if ($null -ne $OnClick) {
if ($OnClick -is [scriptblock]) {
$OnClick = New-UDEndpoint -Endpoint $OnClick -Id ($Id + "onClick")
}
elseif ($OnClick -isnot [UniversalDashboard.Models.Endpoint]) {
throw "OnClick must be a script block or UDEndpoint"
}
if ($OnClick)
{
$OnClick.Register($Id, $PSCmdlet)
}

@{
Expand Down
5 changes: 5 additions & 0 deletions src/UniversalDashboard.MaterialUI/Tests/button.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Enter-SeUrl -Target $Driver -Url "http://localhost:10000/button"

Describe "button" {

It 'works with argumentlist' {
Find-SeElement -Id 'arugmentList' -Driver $Driver | Invoke-SeClick
Get-TestData | Should be "Some Text"
}

It 'has default variant' {
$Element = Find-SeElement -Id 'btnDefault' -Driver $Driver
$Element.GetAttribute("class").Contains('MuiButton-contained') | should be $true
Expand Down
7 changes: 7 additions & 0 deletions src/UniversalDashboard.MaterialUI/dashboard.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ New-UDDashboard -Title "Dashboard" -Theme (get-udtheme basic) -Pages @(
New-UDButton -Text "Submit" -Id "btnClick" -Icon $Icon -OnClick {
Set-TestData -Data "OnClick"
}

$MyVariable = "Some Text"
New-UDButton -Text "Click me!" -Id 'arugmentList' -OnClick (
New-UDEndpoint -Endpoint {
Set-TestData -Data $ArgumentList[0]
} -ArgumentList @($MyVariable)
)
}

New-UDPage -Name 'Card' -Content {
Expand Down

0 comments on commit 20b874e

Please sign in to comment.