diff --git a/src/UniversalDashboard.MaterialUI/Components/button.jsx b/src/UniversalDashboard.MaterialUI/Components/button.jsx index 8d53e3c4..adf65830 100644 --- a/src/UniversalDashboard.MaterialUI/Components/button.jsx +++ b/src/UniversalDashboard.MaterialUI/Components/button.jsx @@ -24,7 +24,7 @@ const UdButton = props => { const handleClick = () => { if (props.onClick == null) return - props.notifyOfEvent('onClick', '') + props.onClick(); } var icon = props.icon ? ( diff --git a/src/UniversalDashboard.MaterialUI/Scripts/button.ps1 b/src/UniversalDashboard.MaterialUI/Scripts/button.ps1 index 276f1063..dda57aba 100644 --- a/src/UniversalDashboard.MaterialUI/Scripts/button.ps1 +++ b/src/UniversalDashboard.MaterialUI/Scripts/button.ps1 @@ -64,7 +64,7 @@ function New-UDButton { [switch]$FullWidth, [Parameter (Position = 7)] - [object]$OnClick, + [Endpoint]$OnClick, [Parameter (Position = 8)] [ValidateSet("small", "medium", "large")] @@ -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) } @{ diff --git a/src/UniversalDashboard.MaterialUI/Tests/button.tests.ps1 b/src/UniversalDashboard.MaterialUI/Tests/button.tests.ps1 index 60e08863..f2b45b03 100644 --- a/src/UniversalDashboard.MaterialUI/Tests/button.tests.ps1 +++ b/src/UniversalDashboard.MaterialUI/Tests/button.tests.ps1 @@ -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 diff --git a/src/UniversalDashboard.MaterialUI/dashboard.ps1 b/src/UniversalDashboard.MaterialUI/dashboard.ps1 index 69a4096f..fc83793a 100644 --- a/src/UniversalDashboard.MaterialUI/dashboard.ps1 +++ b/src/UniversalDashboard.MaterialUI/dashboard.ps1 @@ -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 {